1. 检查并删除Linux自带的JDK依赖
java -version
如下:
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
查看JDK依赖包
rpm -qa | grep java
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-1.8.0.242.b08-1.el7.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2019c-1.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7.x86_64
删除除了.noarch的其它文件
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.242.b08-1.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.242.b08-1.el7.x86_64
如果删除失败可以切换root用户
su -root
输入密码
2.安装JDK
下载linux版本JDK
解压
tar -zxvf jdk-8u271-linux-x64.tar.gz
编辑profile文件
vim /etc/profile
按 i
键,在最后面输入如下内容
export JAVA_HOME=/diskE/jdk1.8.0_271
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
按esc键,输入:wq
保存退出
重新加载profile文件
source /etc/profile
java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
java
javac