如何在 Solaris 中设置默认 java?

如何在 Solaris 中设置默认 java?

我刚刚安装了最新的 Java/usr/jdk/jdk1.6.0_30

现在我该如何让这个 Java 成为整个操作系统的默认 Java?截至目前,它仍在使用 Java 1.5

谢谢。

答案1

找到了...

$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)

答案2

我觉得仅仅改变符号链接/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)

相关内容