JDK下载:
安装步骤:
1、vi install_java.sh 脚本
#!/bin/bash
#1.Check if Java is installed
if type -p java; then
echo "Java has been installed."
exit 0
else
#2.Installed Java
mkdir -p /opt/java/
tar -zxvf ./jdk-8u251-linux-x64.tar.gz -C /opt/java/
#3.Configure environment variables
echo "JAVA_HOME=/opt/java/jdk1.8.0_251
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
2、将 install_java.sh 脚本与安装tar包放在同一目录下,运行此脚本进行自动化安装
3、给脚本文件加执行权限
chmod +x install_java.sh
4、运行脚本文件,进行安装
./install_java.sh