The best posture for MacOS to switch JDK version

jEnv is an open source tool for MacOS to manage the Java version. This is its official document . It supports both Linux and MacOS. I recently used this tool when updating Burp Suite and thought it was pretty good.

1 Installation

Linux / OS X

$ git clone https://github.com/jenv/jenv.git ~/.jenv

Install Mac OS with Homebrew

$ brew install jenv

2 Basic usage

jEnv does not have the function of installing the Java version and deleting the version. It just saves the trouble of configuring environment variables like this tutorial , so HomeBrew is still used to install the JDK in the tutorial.

2.1 JDK installation

After 2019, Oracle has carried out a series of reforms to the Java business model, and multiple versions of the JDK have begun to appear in the eyes of developers.

Overall, there are three versions of the JDK, namely the Oracle the JDK , the Oracle OpenJDK compiled and third-party vendors to compile the OpenJDK . In fact, all three in the function and no significant difference .

Among them, OpenJDK provides a more comprehensive version. AdoptOpenJDK is a completely free and unbranded version of OpenJDK. Based on the GPL open source agreement (+Classpath Extension), the community version of the OpenJDK binary package is provided in the form of free software. The company can also be safe and assured use.

Even use the following command to install various versions of jdk.

# 选择自己需要的版本
$ brew install AdoptOpenJDK/openjdk/adoptopenjdk8
$ brew install AdoptOpenJDK/openjdk/adoptopenjdk9
$ brew install AdoptOpenJDK/openjdk/adoptopenjdk10
$ brew install AdoptOpenJDK/openjdk/adoptopenjdk11
$ brew install AdoptOpenJDK/openjdk/adoptopenjdk12

# 安装最新版本 OpenJDK
$ brew install AdoptOpenJDK/openjdk/adoptopenjdk

Usually in the installation directory /Library/Java/JavaVirtualMachines, it is necessary to use the JDK HOME directory when configuring the jEnv.

2.2 Configure jEnv

View the current Java version that jEnv can manage

$ jenv versions
  system
  oracle64-1.6.0.39
* oracle64-1.7.0.11 (set by /Users/hikage/.jenv/version)

Add the HOME directory of the JDK to jEnv, you only need to add it once, and then you can change the Java environment in seconds.

$ jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

After using jenv versionsit again , you can see the version number of the Java just added.

2.3 Switch Java version

Configure the global JDK version, and oracle64-1.6.0.39replace the following with the JDK version information listed in your jEnv. (If you are not sure, you can go to the bottom to see the renderings)

$ jenv global oracle64-1.6.0.39

Configure the local JDK version

$ jenv local oracle64-1.6.0.39

3 Final effect

Reference blog:

  1. https://www.cnblogs.com/imzhizi/p/macos-jdk-installation-homebrew.html
  2. https://www.jianshu.com/p/1a147d5515f0

Guess you like

Origin blog.csdn.net/qq_43085611/article/details/112199051