1果元、檢查一下系統(tǒng)中的jdk版本
[root@localhost software]# java -version
顯示:
openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
2独悴、檢測jdk安裝包
[root@localhost software]# rpm -qa | grep java
顯示:
java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2016g-2.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
3骗灶、卸載openjdk
[root@localhost software]# rpm -e --nodeps tzdata-java-2016g-2.el7.noarch
[root@localhost software]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
[root@localhost software]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
[root@localhost software]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
[root@localhost software]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
或者使用
[root@localhost jvm]# yum remove *openjdk*
之后再次輸入rpm -qa | grep java 查看卸載情況:
[root@localhost software]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
4艘策、安裝新的jdk
[root@localhost software]# ll
total 181192
-rw-r--r-- 1 root root 185540433 May 20 2017 jdk-8u131-linux-x64.tar.gz
解壓 jdk-8u131-linux-x64.tar.gz安裝包
[root@localhost software]# mkdir -p /opt/soft
[root@localhost software]# mv jdk-8u131-linux-x64.tar.gz /opt/soft
[root@localhost software]# tar -zxvf jdk-8u131-linux-x64.tar.gz
[root@localhost software]# ln -s jdk1.8.0_131 jdk
5、設(shè)置環(huán)境變量
[root@localhost software]# vim /etc/profile
在最前面添加:
export JAVA_HOME=/opt/soft/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
6、執(zhí)行profile文件
[root@localhost software]# source /etc/profile
7唆涝、檢查新安裝的jdk
[root@localhost software]# java -version
顯示:
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
到此為止,整個安裝過程結(jié)束捏膨。
8、腳本安裝
mkdir -p /opt/soft/
cd /opt/soft/
#download jdk-8u161-linux-x64.tar.gz
#wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz
wget --no-check-certificate --no-cookies --header "Cookie: s_nr=1392900709523; ORA_WWW_PERSONALIZE=v:1~i:6~r:6~g:APAC~l:en~cs:NOT_FOUND~cn:scut; ORASSO_AUTH_HINT=v1.0~20140322121132; ORA_UCM_INFO=3~xxxx21212xxxx~xxxx~xxxx~xxxx@163.com; s_cc=true; oraclelicense=accept-securebackup-cookie; gpw_e24=http%3A%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjava-archive-downloads-javase6-419409.html%23jdk-6u45-oth-JPR; s_sq=%5B%5BB%5D%5D;" http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz
#extract jdk
#tar -xvf jdk-8u161-linux-x64.tar.gz
tar -xvf jdk-8u161-linux-x64.tar.gz
rm -f jdk
ln -s jdk1.8.0_161 jdk
#set environment
export JAVA_HOME="/opt/soft/jdk"
if ! grep "JAVA_HOME=/opt/soft/jdk" /etc/profile
then
echo "export JAVA_HOME=/opt/soft/jdk" | tee -a /etc/profile
echo "export JRE_HOME=${JAVA_HOME}/jre " | tee -a /etc/profile
echo "export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib" | tee -a /etc/environment
echo "export PATH=${JAVA_HOME}/bin:$PATH" | tee -a /etc/profile
fi
#update environment
source /etc/profile
echo "jdk is installed !"