脚本
#安装java
#!/bin/bash
if type -p java; then
echo "Java has been installed."
else
#2.Installed Java , must install wget
wget -c https://repo.huaweicloud.com/java/jdk/8u151-b12/jdk-8u151-linux-arm64-vfp-hflt.tar.gz;
tar -zxvf ./jdk-8u151-linux-arm64-vfp-hflt.tar.gz -C /usr/local/;
mv /usr/local/jdk1.8.0_151 /usr/local/javaJDK;
#3.Configure environment variables
echo "JAVA_HOME=/usr/local/javaJDK" >> /etc/profile
source /etc/profile
echo "PATH=${JAVA_HOME}/bin:${PATH}
CLASSPATH=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/tools.jar
export PATH JAVA_HOME CLASSPATH" >> /etc/profile
source /etc/profile
echo "setting path successful."
java -version
echo "installed successful."
fi
java -version