查看當前java版本java
[root@localhost jdk1.6.0_45]# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)bash
發現默認的仍是系統自帶的1.8,不是配置的1.6。ui
[root@localhost jdk1.6.0_45]# echo $JAVA_HOME
/usr/java/jdk1.6.0_45spa
(該命令輸出JAVA_HOME的環境變量值)輸出爲:/usr/java/jdk1.6.0_45 說明修改完成,但還不是系統默認的jdk環境)it
跑去/etc/bashrc裏面也配置上面1.6的環境變量,最後重啓系統仍是沒有改變。io
4、which java 把默認的java重命名解決上面問題變量
[root@localhost jdk1.6.0_45]# echo $SHELL
/bin/bash
[root@localhost jdk1.6.0_45]# which java
/usr/bin/java
[root@localhost jdk1.6.0_45]# mv /usr/bin/java /usr/bin/java_bak
[root@localhost jdk1.6.0_45]# . /etc/profile
[root@localhost jdk1.6.0_45]# which java
/usr/java/jdk1.6.0_45/bin/java
[root@localhost jdk1.6.0_45]# java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode) jdk