linux安装配置JDK脚本
#!/bin/bash # install jdk and configuring environment variables function installjdk(){ tar -zxf jdk-8u201-linux-x64.tar.gz -C /usr/local cat >> /etc/profile << EOF export JAVA_HOME=/usr/local/jdk1.8.0_201 export PATH=\$PATH:\$JAVA_HOME/bin export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar EOF } #-------------------------- testing jdk-------------------------- echo "========= Start to install JDK ==============" source /etc/profile if [ -n "$JAVA_HOME" ];then echo "JDK already installed" java -version else if [ -f "./jdk-8u201-linux-x64.tar.gz" ];then installjdk source /etc/profile java -version echo "use the 'source /etc/profile' command to update local variables" else echo "Missing 'jdk-8u201-linux-x64.tar.gz' file in statistical catalogue" echo "Failed to install JDK" fi fi echo "========= End installation of JDK ==========="