Install OpenJDK 11 on macOS

This article will show you how to install openJDK 11 on macOS

Download OpenJDK 11

https://aka.ms/download-jdk/microsoft-jdk-11.0.18-macOS-x64.tar.gz

Unpackage tar.gz file

# Unpackage openjdk file
tar -xf microsoft-jdk-11.0.18-macos-x64.tar.gz

# Rename folder to openjdk-11 (optional)
mv jdk-11.0.18+10 jdk-11

Move openjdk file to mac library

# List all available java libraries
/usr/libexec/java_home -V
# Example output:
Matching Java Virtual Machines (2):
    17 (x86_64) "Oracle Corporation" - "OpenJDK 17" /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
    1.8.331.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
# Move entire jdk-11.0.18+10 folder to /Library/Java/JavaVirtualMachines/
sudo mv jdk-11.0.18+10/ /Library/Java/JavaVirtualMachines/
# Confirm change
ls /Library/Java/JavaVirtualMachines/
# output
jdk-17.jdk	jdk-11.0.18+10

Set up java home in .bash_profile

# To use default jdk version in terminal, update .bash_profile and add below line 
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.18+10/Contents/Home
# Save and exit.
# Confirm java home 
$ java -version
# Example output
openjdk version "11.0.18" 2023-01-17 LTS
OpenJDK Runtime Environment Microsoft-7208460 (build 11.0.18+10-LTS)
OpenJDK 64-Bit Server VM Microsoft-7208460 (build 11.0.18+10-LTS, mixed mode)

Remove JDK from macOS

# Run below command to remove specific jdk

rm -rf /Library/Java/JavaVirtualMachines/<jdk_home_folder>
Scroll to Top