1、检查一下系统中的jdk版本
[root@localhost software]# 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安装包
[root@localhost software]# rpm -qa | grep java
显示:
java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64 python-javapackages-3.4.1-11.el7.noarch tzdata-java-2016g-2.el7.noarch javapackages-tools-3.4.1-11.el7.noarch java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
3、卸载openjdk
[root@localhost software]# rpm -e --nodeps tzdata-java-2016g-2.el7.noarch [root@localhost software]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64 [root@localhost software]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 [root@localhost software]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 [root@localhost software]# 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 software]# rpm -qa | grep java python-javapackages-3.4.1-11.el7.noarch javapackages-tools-3.4.1-11.el7.noarch
4.下载好jdk(linux版本)通过ftp5直接放在/opt/文件夹下
[root@localhost software]# mkdir -p /usr/lib/jvm [root@localhost software]# tar -zxvf jdk-8u131-linux-x64.tar.gz -C /usr/lib/jvm
解压到/usr/lib/jvm/文件夹下
5.设置环境变量
[root@localhost software]# vim /etc/profile
在最后面添加:
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_131 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
6、执行profile文件
[root@localhost software]# source /etc/profile
7、检查新安装的jdk
[root@localhost software]# java -version
显示:
java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
到此为止,整个安装过程结束。
如果是RPM安装包执行如下安装代码:
rpm -i jdk-8u151-linux-x64.rpm
转载:https://www.cnblogs.com/fangts/p/8947230.html