使用alternatives切换red hat linux的jdk版本
第一次接触到Red Hat Enterprise Linux感觉跟之前熟悉的Centos Ubuntu Fedora还是有些差别的,可能是因为环境配置不同吧
先讲一讲背景吧,我想要在这样的linux服务器上部署一下持续集成的环境,也就是说安装一个tomcat和hudson,很简单的内容。
但是发现我查看java版本的时候出现了没遇到过的情况。
This script is a placeholder for the /usr/bin/javac
master link required by jpackage.org conventions. libgcj's
rmiregistry, rmic and jar tools are now slave symlinks to these
masters, and are managed by the alternatives(8) system.
This change was necessary because the rmiregistry, rmic and jar tools
installed by previous versions of libgcj conflicted with symlinks
installed by jpackage.org JVM packages.
也就是说系统的jdk是由alternatives托管的libgcj,然后我跟踪了一下,找到了服务器上还有几个可以用的JDK目录,所以现在我的任务就是切换alternatives的jdk,让其能够指向可用的原版jdk.
忘了先介绍一下gcj, GNU Compiler for Java,是GNU的一个开源java编译器,具体的内容可以再到网上搜搜看
于是我在网上搜了一下,解决了这个问题,步骤为
1.先将可用的JDK添加到alternatives中:
[root@eric-laptop sbin]# ./alternatives --install /usr/bin/java java /usr/share/jdk1.6.XXXX/bin/java 300
[root@eric-laptop sbin]# ./alternatives --install /usr/bin/javac javac /usr/share/jdk1.6.XXXX/bin/javac 300
2.然后display一下alternatives中可用的jdk列表
[root@eric-laptop sbin]# ./alternatives --display java
java - status is manual.
link currently points to /usr/share/java/libgcj-java-placeholder.sh
/usr/share/java/libgcj-java-placeholder.sh - priority 100
slave rmiregistry: /usr/bin/grmiregistry
slave rmiregistry.1.gz: /usr/share/man/man1/grmiregistry.1.gz
/usr/share/jdk1.6.XXXX/bin/java - priority 300
slave rmiregistry: (null)
slave rmiregistry.1.gz: (null)
Current `best' version is /usr/share/java/libgcj-java-placeholder.sh.
[root@eric-laptop sbin]# ./alternatives --display javac
javac - status is auto.
link currently points to /usr/share/java/libgcj-javac-placeholder.sh
/usr/share/java/libgcj-javac-placeholder.sh - priority 100
slave jar: /usr/bin/gjar
slave rmic: /usr/bin/grmic
slave jar.1.gz: /usr/share/man/man1/gjar.1.gz
slave rmic.1.gz: /usr/share/man/man1/grmic.1.gz
/usr/share/jdk1.6.XXXX/bin/javac - priority 300
slave jar: (null)
slave rmic: (null)
slave jar.1.gz: (null)
slave rmic.1.gz: (null)
Current `best' version is /usr/share/java/libgcj-javac-placeholder.sh.
3.确认已经将好用的JDK添加到alternatives中后,开始配置alternatives
[root@eric-laptop sbin]# ./alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/share/java/libgcj-java-placeholder.sh
2 /home/webspher/jdk1.6.XXXX/bin/java
这时候选择2即可更改到新的java中
同理操作[root@eric-laptop sbin]# ./alternatives --config javac
操作完之后就可以查看一下java的版本
java -version了 可以正常使用了