1. 程式人生 > >Shell指令碼 centOS7中自動安裝JDK

Shell指令碼 centOS7中自動安裝JDK

#切換到root許可權
sudo su


#create java dir
java_file="/usr/local/java"


if [ ! -d "$java_file" ];
then
 mkdir $java_file
fi


cd /usr/local/java


if [ ! -f "jdk-8u131-linux-x64.tar.gz" ];
then
 wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
fi


if [ ! -d "jdk1.8.0_131" ];
then
 tar -xvf jdk-8u131-linux-x64.tar.gz
fi


#set environment
export JAVA_HOME="/usr/local/java/jdk1.8.0_131"
if ! grep "JAVA_HOME=/usr/local/java/jdk1.8.0_131" /etc/environment
then
    echo "JAVA_HOME=/usr/local/java/jdk1.8.0_131" | sudo tee -a /etc/environment
    echo "export JAVA_HOME" | sudo tee -a /etc/environment
    echo "PATH=$PATH:$JAVA_HOME/bin" | sudo tee -a /etc/environment
    echo "export PATH" | sudo tee -a /etc/environment
    echo "CLASSPATH=.:$JAVA_HOME/lib" | sudo tee -a /etc/environment
    echo "export CLASSPATH" | sudo tee -a /etc/environment
fi


source /etc/environment
echo "jdk is installed !"

如果系統中無 wget就安裝一下

archlinux pacman -S wget

ubuntu debian apt-get install wget

fedora yun install wget

cenhOS yum -y install wget

等等..