Manage Multiple Azul Zulu Versions on macOS
If you use a DMG installer to install Azul Zulu, the default installation directory is /Library/Java/JavaVirtualMachines/<azul_zulu_folder>/. The <azul_zulu_folder> represents the type of Azul Zulu package (JDK or JRE) and its version, for example zulu-11.jdk.
JavaVirtualMachines
You can view all Azul Zulu versions installed on your Mac by navigating to the JavaVirtualMachines directory. Use Finder or launch Terminal and run the following command:
% ls -1 /Library/Java/JavaVirtualMachines/
zulu-11.jdk
zulu-13.jre
zulu-15.jdk
zulu-8.jdk
Using java_home
Use the java_home tool to check which version of Java is used by default:
% /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home
Listing All Installed Java Versions
To list all installed JREs and JDKs including their CPU architecture, use the -V flag:
% /usr/libexec/java_home -V
Matching Java Virtual Machines (4):
20.0.1 (arm64) "Azul Systems, Inc." - "Zulu 20.30.11" /Library/Java/JavaVirtualMachines/zulu-20.jdk/Contents/Home
17.0.7 (arm64) "Azul Systems, Inc." - "Zulu 17.42.19" /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home
11.0.19 (arm64) "Azul Systems, Inc." - "Zulu 11.64.19" /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
1.8.0_372 (arm64) "Azul Systems, Inc." - "Zulu 8.70.0.23" /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/zulu-20.jdk/Contents/Home
|
Note
|
/usr/libexec/java_home -V evaluates the JAVA_VERSION environment variable. To list all installed JVMs regardless of that setting, unset JAVA_VERSION before calling it.
|
Using a Different Java Version
To execute a different version of Java, which is available on your system based on the list provided with the -V flag, use the following command:
% /usr/libexec/java_home -v 11 --exec java -version
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment Zulu11.48+21-CA (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM Zulu11.48+21-CA (build 11.0.11+9-LTS, mixed mode)
# For Java 8, you need to use "1.8"
% /usr/libexec/java_home -v 1.8 --exec java -version
openjdk version "1.8.0_342"
OpenJDK Runtime Environment (Zulu 8.64.0.15-CA-macos-aarch64) (build 1.8.0_342-b07)
OpenJDK 64-Bit Server VM (Zulu 8.64.0.15-CA-macos-aarch64) (build 25.342-b07, mixed mode)
Setting the Default Java Version
To set a specific Java version as the default for the current shell session, set the JAVA_VERSION environment variable. By default, /usr/bin/java selects the highest installed Java version. The following example changes the default to Zulu 11 on a Mac where Zulu 11, Zulu 17, and Zulu 20 are all installed:
% export JAVA_VERSION=11
% java -version
openjdk version "11.0.19" 2023-04-18 LTS
OpenJDK Runtime Environment Zulu11.64+19-CA (build 11.0.19+7-LTS)
OpenJDK 64-Bit Server VM Zulu11.64+19-CA (build 11.0.19+7-LTS, mixed mode)
To persist this setting, add the export line to your shell startup script, for example $HOME/.zshrc.
|
Note
|
For Java 8, use JAVA_VERSION=1.8. Using JAVA_VERSION=8 would match Java 18 or higher instead.
|
|
Note
|
You can also specify a minimum patch version, for example: JAVA_VERSION=17.0.11.
|
Alternatively, set JAVA_HOME using java_home:
% export JAVA_HOME=$(/usr/libexec/java_home -v 11)
% java -version
openjdk version "11.0.19" 2023-04-18 LTS
OpenJDK Runtime Environment Zulu11.64+19-CA (build 11.0.19+7-LTS)
OpenJDK 64-Bit Server VM Zulu11.64+19-CA (build 11.0.19+7-LTS, mixed mode)