Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Free switching of mac Apple Multi-version jdk

Shulou Source: shulou.com Published: 2022-06-03 06:39:35 10月02日 Update

Scene

The tools on hand sometimes rely on a lower version of jdk and sometimes require a higher version of jdk. How to switch back and forth freely between different versions of jdk?

Installation

The first choice is to download the dmg installation package from the official website, address: https://www.oracle.com/technetwork/java/javase/downloads/index.html

How to install dmg, skip here, do not know their own Baidu bar.

My installation directory:

/ Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk

/ Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk

Configure the environment

Method 1:

Vi .bash _ profile / / Editor

Source .bash _ profile / / effective new configuration

# set JDK 7

Export JAVA_7_HOME= `/ usr/libexec/java_home-v 1.7`

# set JDK 8

Export JAVA_8_HOME= `/ usr/libexec/java_home-v 1.8`

# default JDK 8

Export JAVA_HOME=$JAVA_8_HOME

# alias command to dynamically switch JDK version

Alias jdk7= "export JAVA_HOME=$JAVA_7_HOME"

Alias jdk8= "export JAVA_HOME=$JAVA_8_HOME"

Method 2:

# hard coding method, not recommended

Export JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home

Export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home

Export JAVA_HOME=$JAVA_8_HOME / / default JDK

Alias jdk7='export JAVA_HOME=$JAVA_7_HOME'

Alias jdk8='export JAVA_HOME=$JAVA_8_HOME'

View

View the current version

Java-version

View the installation path of the default jdk

/ usr/libexec/java_home

View the installation path for jdk 1.7

/ usr/libexec/java_home-v 1.7

In previous versions, without this command, you should use a fixed / Library/Java/Home directory, that is, write to death directly in the environment variable.

Today's featured recommendation

JMeter Interface Test-if Controller

JMeter database operation

Jmeter Interface Test-regular expression

JMeter returns garbled code in Chinese

Jmeter interface testing-parameterization

JMeter Interface testing-Basics

Test-impression

Add Wechat to the consulting work

scan a QR code

Welcome self-recommendation and recommendation, need Wechat to push resume!

Please poke the QR code below to learn more.

Tags: Version test interface method recommendation switch command sometimes environment directory path 2D QR code configuration free different clear between that is garbled Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft Shulou Tech Info vpn Redmi