1、查看自带Java版本
[root@localhost /]# java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
2、查询OpenJDK
[root@localhost /]# rpm -qa|grep java
python-javapackages-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64
java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.2.el7.x86_64
tzdata-java-2018c-1.el7.noarch
3、删除openJDK版本
[root@localhost /]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64
[root@localhost /]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64[root@localhost /]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
[root@localhost /]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.2.el7.x86_64
再次查询OpenJDK,openJDK已删除
[root@localhost /]# rpm -qa|grep java
python-javapackages-3.4.1-11.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
tzdata-java-2018c-1.el7.noarch
4、查看Linux版本位数
[root@localhost /]# getconf LONG_BIT
64
下载对应位数的jdk版本。
5、下载JDK
jdk-8u221-linux-x64.tar.gz
网址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
6、解压
使用MobaXterm将压缩包传到指定文件夹/usr/local/share/applications/,解压缩到/usr/java/
[root@localhost applications]# tar -zxvf jdk-8u221-linux-x64.tar.gz -C /usr/java
7、配置环境变量
[root@localhost ~]# vi /etc/profile #编辑环境变量表,最后面加上下面的配置信息
#set java env
JAVA_HOME=/usr/java/jdk1.8.0_211
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH[root@localhost ~]# source /etc/profile #使新的配置文件生效
8、测试
[root@localhost ~]# java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
成功。