卸载系统中自带JDK
如果系统中并没有安装jdk,可以忽略直接下一步安装
查看系统使用中jdk版本:
java -version
[root@localhost jdk1.8.0_231]# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
查看所有已安装java相关的软件包:
rpm -qa | grep java
[root@localhost jdk1.8.0_231]# rpm -qa | grep java
java-1.7.0-openjdk-headless-1.7.0.241-2.6.20.0.el7_7.x86_64
java-1.8.0-openjdk-headless-1.8.0.232.b09-0.el7_7.x86_64
java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64
java-1.7.0-openjdk-1.7.0.241-2.6.20.0.el7_7.x86_64
tzdata-java-2019c-1.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
python-javapackages-3.4.1-11.el7.noarch
如上命令结果中可以发现使用中的jdk版本即java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64
,但为了防止其它已安装jdk影响,建议把所有openjdk给删掉,如下:
[root@localhost jdk1.8.0_231]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.232.b09-0.el7_7.x86_64
[root@localhost jdk1.8.0_231]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64
[root@localhost jdk1.8.0_231]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.241-2.6.20.0.el7_7.x86_64
[root@localhost jdk1.8.0_231]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.241-2.6.20.0.el7_7.x86_64
安装JDK (官方下载JDK)
在指定安装目录(我习惯放在/usr/softinstall/
目录下)解压:
tar -xzvf jdk-8u231-linux-x64.tar.gz
jdk的tar.gz版不需要安装,只需要配置环境变量即可:
vim /etc/profile
export JAVA_HOME=/usr/softinstall/jdk1.8.0_231
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
source /etc/profile
测试:
java -version
[root@lee000 jdk1.8.0_231]# java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)