安裝JDK1.7後發現版本不對,默認是系統自帶的JDK1.8。需要更改,這裏使用alternatives處理,參照http://blog.csdn.net/nsrainbow/article/details/43273991文章, 下附原文內容,備忘。只不過自己是rpm安裝的,不需要install 拷貝過去。
centos自帶openJDK,我從別的機器上拷貝了一個dk1.7 到 /usr/java/ 目錄下,然後運行
sudo alternatives --install /usr/bin/java java /opt/jdk1.7.0_71/bin/java 1 sudo alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_71/bin/javac 1 sudo alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_71/bin/jar 1
這樣就登記了一個新的jdk在 alternatives 裏面
然後運行 alternatives --config java 會出現兩個jdk讓我選
[root@host1 java]# alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java + 2 /usr/java/jdk1.7.0_25/bin/java Enter to keep the current selection[+], or type selection number: 2
我選2,jdk就切換成 oracle jdk了
[root@host1 java]# java -version java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
後來發現alternatives 還是很好用的:
[root@mongod_2 ~]# vim ./hello.sh #!/bin/bash # ver="0.1" echo $ver [root@mongod_2 ~]# cp hello.sh hello2.sh [root@mongod_2 ~]# vim hello2.sh #!bin/bash # ver="0.2" echo $ver [root@mongod_2 ~]# alternatives --install /usr/local/hello hello /root/hello.sh 1 [root@mongod_2 ~]# alternatives --install /usr/local/hello hello /root/hello2.sh 1 [root@mongod_2 ~]# alternatives --config hello [root@mongod_2 ~]# alternatives --config hello There are 2 programs which provide 'hello'. Selection Command ----------------------------------------------- * 1 /root/hello.sh + 2 /root/hello2.sh