Linux installs multiple versions of jdk to switch

  • 2020-05-27 08:00:08
  • OfStack

This article shares the specific method of installing multiple versions of Linux jdk for your reference, the specific content is as follows

1. Upload jdk7 and jdk8 packages

2. Unzip


[root@localhost webapps]# tar -zxvf /package/jdk-7u80-linux-x64.tar.gz 

3. Configure the jdk variable


 vi /etc/profile

export JAVA_HOME=/package/jdk1.7.0_80
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

4. java -version

5. Set the serial number for jdk1.7


[xxx@localhost home]$ alternatives --install /usr/bin/java java /package/jdk1.7.0_80 3

6. Install jdk1. 8


[xxx@localhost home]$ alternatives --install /usr/bin/java java /package/jdk1.8.0_124 2

7. Select the number for jdk -- switch the jdk version


[root@localhost ~]# java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
[root@localhost ~]# alternatives --config java

There are 3 programs which provide 'java'.

 Selection  Command
-----------------------------------------------
* 1      /package/jdk1.8.0_121/java
  2      /package/jdk1.8.0_121/bin/java
 + 3      /package/jdk1.7.0_80/bin/java

Enter to keep the current selection[+], or type selection number: 2
[root@localhost ~]# java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)


Related articles: