linux下的alternative的多版本管理

centos是自带的openjdk,安装eclipse时, 下载最新的jdk。解压到/usr/java目录下。

tar zxvf jre-8u121-linux-x64.tar.gz

设置环境变量

#vi /etc/profile

export JAVA_HOME="/usr/java/jdk1.8.0_121"

export CLASS_PATH=".:/usr/java/jdk1.8.0_121/lib/dt.jar:/usr/java/jdk1.8.0_121/lib/tools.jar"

export PATH="$PATH:/usr/java/jdk1.8.0_121/bin"

#source /etc/profile

2[[email protected] ~]# alternatives --install /usr/bin/java  java  /usr/java/jdk1.6.0_21/bin/java  400
3[[email protected] ~]# alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_21/bin/javac 400

现在可以看看注册的成果了:

 
01[[email protected] ~]# alternatives --config java
02  
03There are 3 programs which provide 'java'.
04  
05  Selection    Command
06-----------------------------------------------
07*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
08   2           /usr/java/jre1.6.0_21/bin/java
09   3           /usr/java/jdk1.6.0_21/bin/java
10  
11Enter to keep the current selection[+], or type selection number:

这里输入想要用的 java 就可以了,例如我选在了第2个。我们看看 /usr/bin/java的变化:

 
1[[email protected] ~]# ll /usr/bin/java
2lrwxrwxrwx  1 root root 22 Dec 17  2009 /usr/bin/java -> /etc/alternatives/java
3[[email protected] ~]# ll /etc/alternatives/java
4lrwxrwxrwx  1 root root 30 Aug 23 15:03 /etc/alternatives/java -> /usr/java/jre

相关推荐