Alternative multi-version management under linux

Centos comes with openjdk. When installing eclipse, download the latest jdk. Extract it to the /usr/java directory.

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

Set environment variables

#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

Now you can see the results of the registration:

 
01 [[email protected] ~]# alternatives --config java
02   
03 There 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   
11 Enter to keep the current selection[+], or type selection number:

Just enter the java you want to use here, for example, I chose the second one. Let's look at the changes in /usr/bin/java:

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326332429&siteId=291194637