banner
lca

lca

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

Setting multiple Java versions on Mac.

Setting up multiple Java versions on a Mac can be achieved using the alias command. Different Java versions can be set with different variables, which can be referenced later using aliases.

The following is the configuration file for 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 of configuration to ~/.zshrc: source ~/.bash_profile, to synchronize the ~/.bash_profile file. Once the setup is complete, all configuration files can be added to ~/.bash_profile only.

#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 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.