1、检查一下系统中的jdk版本
#java -version
显示:
[root@localhost etc]# java -version openjdk version "1.8.0_102" OpenJDK Runtime Environment (build 1.8.0_102-b14) OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
2、检测jdk安装包
#rpm -qa | grep java
显示:
[root@localhost etc]# rpm -qa | grep java java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 javapackages-tools-3.4.1-11.el7.noarch java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 tzdata-java-2016g-2.el7.noarch python-javapackages-3.4.1-11.el7.noarch java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
3、卸载openjdk
[root@localhost etc]# rpm -e --nodeps tzdata-java-2016g-2.el7.noarch [root@localhost etc]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64 [root@localhost etc]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 [root@localhost etc]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 [root@localhost etc]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
或者使用
[root@localhost jvm]# yum remove *openjdk*
之后再次输入rpm -qa | grep java 查看卸载情况:
[root@localhost etc]# rpm -qa | grep java javapackages-tools-3.4.1-11.el7.noarch python-javapackages-3.4.1-11.el7.noarch
4、安装新的jdk
首先到jdk官网上下载你想要的jdk版本,下载完成之后将需要安装的jdk安装包放到Linux系统指定的文件夹下,并且命令进入该文件夹下
解压 apache-tomcat-8.5.28.tar.gz 安装包
[root@localhost local]# tar -zxvf apache-tomcat-8.5.28.tar.gz -C /usr/local/java
5、设置环境变量
[root@localhost local]# vim /etc/profile
添加:
JAVA_HOME=/usr/local/java/jdk1.8.0_161
JRE_HOME=/usr/local/java/jdk1.8.0_161/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JAVA_BIN PATH CLASSPATH
6、执行profile文件
[root@localhost local]# source /etc/profile
这样可以使配置不用重启即可立即生效。
7、检查新安装的jdk
[root@localhost local]# java -version
显示:
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)