Multi-version management of JDK under Linux
In the development of the project, no matter what language can not avoid multiple version of the environmental management issues (although this article in the JDK as an example, but not limited to the JDK), how to achieve a rapid environment upgrade and switching is really a thoughtful thing!
Installing the JDK
Experimental installation of two versions:
- Jdk-7u80-linux-x64.tar.gz
- Jdk-8u144-linux-x64.tar.gz
Download
- wget http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz
- wget http://download.oracle.com/otn/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz
Installation
I installed it in the/opt.
- TAR-ZXVF jdk-7u80-linux-x64.tar.gz
- Create a directory in/OPT: sudo mkdir java
- sudo mv Jdk1.7.0_80/opt/java
JDK8 is the same way.
Creating a soft connection
- sudo ln-s jdk1.7.0_80 jdk
- Use JDK7 by default
Changing environment variables
echo $PATH output, in fact, this corresponds to the window System PATH
CD ~ Go to the home directory
sudo vi. BASHRC
Last added: Export path=/opt/java/jdk/bin: $PATH
source. BASHRC
At this point directly can output: Java-verson, for Java7
If one day environment to upgrade, such as to upgrade Jdk7 to JDK8, we only need to change the soft connection address:
- Remove the original JDK soft connection
- Rebuild: sudo ln-s jdk1.8.0_144 jdk
- The upgrade is complete at this time
Review
The above version management approach is ubiquitous in Linux, such as Python in the form of soft joins.
Based on JENV tool management
Input at this time: jenv output information: jenv 0.4.3-18-G66BB5B1
With the JDK already installed, we just need to add the JDK to the jenv:
- Jenv add/opt/jdk1.7.0_80
- Jenv add/opt/jdk1.8.0_144
Look at the path of Java currently in use
Jenv which Java
View the Java version you can set
Jenv versions
Use a version of the JDK (global)
JENV Global 1.8
Remove some of the unused version, such as the default will be added 3 names, in fact, only one can be deleted
Jenv Remove 1.8.0.121
Multi-version management of JDK under Linux