1.卸载系统中自带的openjdk
# 先查找
rpm -qa|grep jdk
# 卸载
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.242.b08-1.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7.x86_64
# 验证一下
rpm -qa|grep java
java -version
2.下载jdk
3.解压压缩包
tar -zxvf jdk-8u202-linux-x64.tar.gz
# 移动到 /usr/local目录下
mv jdk-8u202-linux-x64 /usr/local
4.配置环境变量
vim /etc/profile
# 在文件最下面插入下面代码
# jdk
export JAVA_HOME=/usr/local/jdk1.8.0_202
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
java -version