banner
lca

lca

真正的不自由,是在自己的心中设下牢笼。

Setting multiple Java versions on macOS

To set multiple Java versions on a Mac, you can use the alias command to achieve this. Different Java versions are set using different variables, which are then referenced through aliases.

Below is the configuration file for the Java environment variables on my computer. The configuration file is located at ~/.bash_profile. If you are using zsh on your Mac, you need to add a line to the ~/.zshrc configuration file: source ~/.bash_profile, to sync the ~/.bash_profile file. Once the setup is complete, all subsequent configuration changes only need to be added to the ~/.bash_profile file.

#java

# Java config
export JAVA_17_HOME="/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home"
export JAVA_16_HOME="/Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home"
export JAVA_8_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home"
export JAVA_801_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home"
export JAVA_7_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home"

# config alias
alias jdk17="export JAVA_HOME=$JAVA_17_HOME"
alias jdk16="export JAVA_HOME=$JAVA_16_HOME"
alias jdk8="export JAVA_HOME=$JAVA_8_HOME"
alias jdk801="export JAVA_HOME=$JAVA_801_HOME"
alias jdk7="export JAVA_HOME=$JAVA_7_HOME"

# config default jdk
export JAVA_HOME=$JAVA_16_HOME
export PATH="$JAVA_HOME:$PATH"

Versions include:

1.7.0_25
1.7.0_80
1.8.0_201
1.8.0_92
16.0.1
17.0.7

The current default Java version is Java 16. If you need to use Java 17, simply open the terminal and enter java17 to switch to the Java 17 version.

image
Java version download links:

http://www.codebaoku.com/jdk/jdk-oracle-jdk1-8.html#jdk8u201

https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.