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

 centos自带openJDK,我从别的机器上拷贝了一个jdk1.7 到 /usr/java/ 目录下,然后运行 

sudo alternatives --install /usr/bin/java java /opt/jdk1.7.0_71/bin/java 1
sudo alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_71/bin/javac 1
sudo alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_71/bin/jar 1

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

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

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

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
 + 2           /usr/java/jdk1.7.0_25/bin/java

Enter to keep the current selection[+], or type selection number: 2

我选2,jdk就切换成 oracle jdk了

[root@host1 java]# java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)


你可能感兴趣的:(在Centos下用alternative命令切换各个版本的jdk的方法)