jdk环境部署脚本
Linux安装jdk8及环境变量配置
https://www.jianshu.com/p/f000e05f3512
脚本:
1 #!/bin/bash 2 # install jdk and configuring environment variables 3 function installjdk(){ 4 tar -zxf jdk-8u201-linux-x64.tar.gz -C /usr/local 5 cat >> /etc/profile << EOF 6 export JAVA_HOME=/usr/local/jdk1.8.0_201 7 export PATH=\$PATH:\$JAVA_HOME/bin 8 export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar 9 EOF 10 } 11 12 #-------------------------- testing jdk-------------------------- 13 echo "========= Start to install JDK ==============" 14 source /etc/profile 15 if [ -n "$JAVA_HOME" ];then 16 echo "JDK already installed" 17 java -version 18 else 19 if [ -f "./jdk-8u201-linux-x64.tar.gz" ];then 20 installjdk 21 source /etc/profile 22 java -version 23 echo "use the 'source /etc/profile' command to update local variables" 24 else 25 echo "Missing 'jdk-8u201-linux-x64.tar.gz' file in statistical catalogue" 26 echo "Failed to install JDK" 27 fi 28 fi 29 echo "========= End installation of JDK ==========="