rpm -ivh jdk-8u131-linux-x64.rpm
2、查看相关配置信息
[root@localhost ~]# update-alternatives --display java|grep priority
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64/jre/bin/java - family java-1.7.0-openjdk.x86_64 priority 1700191
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre/bin/java - family java-1.8.0-openjdk.x86_64 priority 1800181
/usr/java/jdk1.8.0_131/jre/bin/java - priority 180131
#重点关注 链接当前指向 和 优先级(1700191)
#通常我们将优先级设置的比原openjdk优先级要小。
3、开始配置
sudo update-alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_131/bin/java 1700100
#安装jdk1.8的路径
/usr/java/jdk1.8.0_131/bin/java
4、使用JDK1.8作为首选java命令
[root@localhost ~]# sudo update-alternatives --config java
共有 4 个提供“java”的程序。
选项 命令
-----------------------------------------------
1 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64/jre/bin/java)
*+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre/bin/java)
3 /usr/java/jdk1.8.0_131/jre/bin/java
4 /usr/java/jdk1.8.0_131/bin/java
按 Enter 保留当前选项[+],或者键入选项编号:4
5、查看版本
[root@localhost ~]# 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)