linux下选择java版本

使用alternatives命令完成,必须具有root权限。

alternative命令介绍

alternatives version 1.3.30.2 - Copyright (C) 2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: alternatives --install <link> <name> <path> <priority>
                    [--initscript <service>]
                    [--slave <link> <name> <path>]*
       alternatives --remove <name> <path>
       alternatives --auto <name>
       alternatives --config <name>
       alternatives --display <name>
       alternatives --set <name> <path>
看当前java版本:

-bash-3.2$ /usr/sbin/alternatives --display java
java - status is auto.
 link currently points to /usr/lib/jvm/jre-1.6.0-sun/bin/java
/usr/lib/jvm/jre-1.6.0-sun/bin/java - priority 1603
 slave javaws_bin: /usr/lib/jvm/jre-1.6.0-sun/bin/javaws
 slave jcontrol: /usr/lib/jvm/jre-1.6.0-sun/bin/jcontrol
 slave keytool: /usr/lib/jvm/jre-1.6.0-sun/bin/keytool
 slave orbd: /usr/lib/jvm/jre-1.6.0-sun/bin/orbd
 slave pack200: /usr/lib/jvm/jre-1.6.0-sun/bin/pack200
 slave policytool: /usr/lib/jvm/jre-1.6.0-sun/bin/policytool
 slave rmid: /usr/lib/jvm/jre-1.6.0-sun/bin/rmid
 slave rmiregistry: /usr/lib/jvm/jre-1.6.0-sun/bin/rmiregistry
 slave servertool: /usr/lib/jvm/jre-1.6.0-sun/bin/servertool
 slave tnameserv: /usr/lib/jvm/jre-1.6.0-sun/bin/tnameserv
 slave unpack200: /usr/lib/jvm/jre-1.6.0-sun/bin/unpack200
 slave jre_exports: /usr/lib/jvm-exports/jre-1.6.0-sun
 slave jre: /usr/lib/jvm/jre-1.6.0-sun
 slave javaws: /usr/lib/jvm/jre-1.6.0-sun/javaws
 slave java.1: /usr/share/man/man1/java-java-1.6.0-sun-compat.1
 slave javaws.1: /usr/share/man/man1/javaws-java-1.6.0-sun-compat.1
 slave keytool.1: /usr/share/man/man1/keytool-java-1.6.0-sun-compat.1
 slave orbd.1: /usr/share/man/man1/orbd-java-1.6.0-sun-compat.1
 slave pack200.1: /usr/share/man/man1/pack200-java-1.6.0-sun-compat.1
 slave policytool.1: /usr/share/man/man1/policytool-java-1.6.0-sun-compat.1
 slave rmid.1: /usr/share/man/man1/rmid-java-1.6.0-sun-compat.1
 slave rmiregistry.1: /usr/share/man/man1/rmiregistry-java-1.6.0-sun-compat.1
 slave servertool.1: /usr/share/man/man1/servertool-java-1.6.0-sun-compat.1
 slave tnameserv.1: /usr/share/man/man1/tnameserv-java-1.6.0-sun-compat.1
 slave unpack200.1: /usr/share/man/man1/unpack200-java-1.6.0-sun-compat.1
/usr/lib/jvm/jre-1.4.2-gcj/bin/java - priority 1420
 slave javaws_bin: (null)
 slave jcontrol: (null)
 slave keytool: /usr/lib/jvm/jre-1.4.2-gcj/bin/keytool
 slave orbd: (null)
 slave pack200: (null)
 slave policytool: (null)
 slave rmid: (null)
 slave rmiregistry: /usr/lib/jvm/jre-1.4.2-gcj/bin/rmiregistry
 slave servertool: (null)
 slave tnameserv: (null)
 slave unpack200: (null)
 slave jre_exports: /usr/lib/jvm-exports/jre-1.4.2-gcj
 slave jre: /usr/lib/jvm/jre-1.4.2-gcj
 slave javaws: (null)
 slave java.1: (null)
 slave javaws.1: (null)
 slave keytool.1: (null)
 slave orbd.1: (null)
 slave pack200.1: (null)
 slave policytool.1: (null)
 slave rmid.1: (null)
 slave rmiregistry.1: (null)
 slave servertool.1: (null)
 slave tnameserv.1: (null)
 slave unpack200.1: (null)
Current `best' version is /usr/lib/jvm/jre-1.6.0-sun/bin/java.
安装新版本:

-bash-3.2$ /usr/sbin/alternatives --install /usr/bin/java java /home/bio/software/jdk1.6.0_06-x86_64/bin/java 1664
-bash-3.2$ /usr/sbin/alternatives --install /usr/bin/javac javac /home/bio/software/jdk1.6.0_06-x86_64/bin/javac 1664
[root@localhost sbin]# ./alternatives --config java

[root@localhost sbin]# ./alternatives --config javac
分别选择,搞定。

你可能感兴趣的:(linux)