Java

如何在 Solaris 中設置預設 java?

  • February 16, 2017

我剛剛安裝了最新的java/usr/jdk/jdk1.6.0_30

現在如何使這個 java 成為整個作業系統的預設 java?截至目前,它仍在使用 java 1.5

謝謝。

找到了…

$which java
/usr/bin/java
$ls -ld /usr/bin/java
lrwxrwxrwx 1 root other 16 Apr 8 12:41 /usr/bin/java -> ../java/bin/java
$rm /usr/bin/java
$ln -s /usr/jdk/jdk1.6.0_27/bin/java /usr/bin/java
$java -version
java version "1.6.0_27"
Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
Java HotSpot(TM) Server VM (build 20.2-b06, mixed mode)

我覺得僅僅改變符號連結/usr/bin/java是不夠的,因為 /usr/bin 中有不止一個 Java 符號連結:

# ls -l /usr/bin/java*
lrwxrwxrwx   1 root     other         16 May 21  2015 /usr/bin/java -> ../java/bin/java
lrwxrwxrwx   1 root     other         17 May 21  2015 /usr/bin/javac -> ../java/bin/javac
lrwxrwxrwx   1 root     other         19 May 21  2015 /usr/bin/javadoc -> ../java/bin/javadoc
lrwxrwxrwx   1 root     other         17 May 21  2015 /usr/bin/javah -> ../java/bin/javah
lrwxrwxrwx   1 root     other         17 May 21  2015 /usr/bin/javap -> ../java/bin/javap
lrwxrwxrwx   1 root     other         18 Jul 21  2015 /usr/bin/javaws -> ../java/bin/javaws

相反,我會利用它/usr/java本身就是一個符號連結的事實並替換它而不是 6+ 其他。以下是我將 JDK 8 設為預設值的方法:

# cd /usr
# rm java
# ln -s jdk/jdk1.8.0_121 java
# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)

引用自:https://serverfault.com/questions/389107