在Centos下用alternatives命令切换各个版本的jdk的方法

自己通过rpm安装了个jdk1.8,默认安装在/usr/java中,应调试需要,在服务器的/usr/local/java目录里安装jdk-6u25-linux-x64.bin,默认创建/usr/local/java/jdk1.6.0_25,需要切换着使用JDK执行如下命令:

[root@iZ23udjr1lgZ java]# alternatives --install /usr/bin/java java /usr/local/java/jdk1.6.0_25/bin/java 1 
[root@iZ23udjr1lgZ java]# alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.6.0_25/bin/javac 1 
[root@iZ23udjr1lgZ java]# alternatives --install /usr/bin/jar jar /usr/local/java/jdk1.6.0_25/bin/jar 1

这样就登记了一个新的jdk在 alternatives 里面

然后运行 alternatives --config java 会出现两个jdk让我选

[root@iZ23udjr1lgZ java]# alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk1.8.0_45/jre/bin/java
   2           /usr/local/java/jdk1.6.0_25/bin/java

Enter to keep the current selection[+], or type selection number: 2
我选2,jdk就切换成1.6 jdk了
[root@iZ23udjr1lgZ java]# java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)

你可能感兴趣的:(centos)