[ubuntu server 16.04下的安装脚本]1.Ubuntu16.04一键安装jdk

【软件版本说明】

软件名 版本号
jdk 1.8.121

1.一键安装jdk脚本

#!/bin/bash  
#this shell to use installing jdk1.8.121 
echo "this shell to use installing jdk1.8.121 "
echo "------------------start to install jdk----------------------"

#sudo su #切换到root权限
mkdir /usr/local/java
cd /usr/local/java
#download jdk 1.8.121
#wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz

wget https://coding.net/u/jamesz2011/p/ubuntu_lib/git/raw/master/jdk/jdk-8u121-linux-x64.tar.gz

#extract jdk
tar -xvf jdk-8u121-linux-x64.tar.gz

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

#update profile
#source /etc/profile  

sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_121/bin/java 300

sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.8.0_121/bin/javac 300

echo "------------------end to install jdk------------------------"

2.install_jdk.sh文件地址:


3.用法:

wget https://coding.net/u/jamesz2011/p/ubuntu_lib/git/raw/master/jdk/install_jdk.sh


sudo chmod a+x install_jdk.sh

sudo source install_jdk.sh

4.验证是否安装成功:

输入 java -versoin [若出现版本号,则安装成功]


[ubuntu server 16.04下的安装脚本]1.Ubuntu16.04一键安装jdk_第1张图片
java -version

你可能感兴趣的:([ubuntu server 16.04下的安装脚本]1.Ubuntu16.04一键安装jdk)