Multi-version management of JDK under Linux

Source: Internet
Author: User
Tags git clone

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
    • git clone https://github.com/gcuisinier/jenv.git ~/.jenv
    • CD ~ You will find one more folder. Jenv, this is Jenv's package.
    • Import the Jenv directory into the environment variableecho ‘export PATH="$HOME/.jenv/bin:$PATH"‘ >> ~/.bash_profile

      echo ‘eval "$(jenv init -)"‘ >> ~/.bash_profile

      source ~/.bash_profile

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.