1.查看当前虚拟机java环境版本: java -version
[root@centos-linux-7 bin]# java -version
java version "1.7.0_111"
OpenJDK Runtime Environment (rhel-2.6.7.2.el7_2-x86_64 u111-b01)
OpenJDK 64-Bit Server VM (build 24.111-b01, mixed mode)
2.查看当前安装版本
[root@centos-linux-7 bin]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64
java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.2.el7_2.x86_64
tzdata-java-2016f-1.el7.noarch
3.删除已安装的openjdk
[root@centos-linux-7 bin]# rpm -e java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64
[root@centos-linux-7 bin]# rpm -e java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.2.el7_2.x86_64
错误:依赖检测失败:
java-headless >= 1:1.6 被 (已安裝) libreoffice-core-1:4.3.7.2-5.el7_2.1.x86_64 需要
libjvm.so()(64bit) 被 (已安裝) libreoffice-ure-1:4.3.7.2-5.el7_2.1.x86_64 需要
在删除包时,会有依赖问题, 所以在rpm -e 时添加 --nodeps 即 nodependencies
[root@centos-linux-7 bin]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.2.el7_2.x86_64
4.查看是否卸载openjdk 成功
[root@centos-linux-7 bin]# java -version
-bash: /usr/bin/java: 没有那个文件或目录 ---成功
5.下载解压jdk包
[root@centos-linux-7 jdk]# tar -zxvf jdk-8u141-linux-x64.tar.gz
6.编辑PATH变量
[root@centos-linux-7 bin]# vim /etc/profile
#java environment
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_141
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin --{JAVA_HOME} centos7
7.配置后生效
[root@centos-linux-7 jdk1.8.0_141]# source /etc/profile
8.检测是否成功安装jdk8
[root@centos-linux-7 jdk1.8.0_141]# java -version
java version "1.8.0_141"
Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)