1、删除自带的OpenJDK

rpm -qa | grep java
rpm -qa | grep gcj
rpm -qa | grep jdk
rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.x86_64
rpm -e --nodeps tzdata-java-2013g-1.el6.noarch
rpm -e --nodeps java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.x86_64
rpm -e --nodeps java_cup-0.10k-5.el6.x86_64
rpm -e --nodeps libgcj-4.4.7-4.el6.x86_64

2、下载JDK安装包

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

3、安装

rpm -ivh jdk-8u171-linux-x64.rpm
cd /usr/java/
ll

4、配置

打开 vim /etc/profile,在末尾添加

export JAVA_HOME=/usr/java/default
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

5、刷新配置

source /etc/profile

6、验证

使用 java -version查看现在的Java版本号。

java version
"1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
05-06 11:07