3 Steps to Install OpenJDK 11 on macOS

This article will show you how to deinstall all preinstalled JDK from the mac OS and then install OpenJDK 11 on it. I used macOS Big Sur (11.7.2) as example.
TL;DR
sudo rm -fr /Users/yourUserName/Library/Java/JavaVirtualMachines/*
sudo rm -fr /Library/Java/JavaVirtualMachines/*
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install openjdk@11
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
java -version- Deinstall all JDK
- Install OpenJDK 11 via brew
- Symlink JDK and check JDK version
- What’s Next
1. Deinstall all JDK
1.1 Firstly, execute followed command in Terminal to check if Java is installed on your laptop.
java -version
1.2 No JDK installed. If the output of step 1.1 is something like the text followed, it means that there is no JDK installed in your system. You can then jump to step 2 “Install OpenJDK 11 via brew”.
The operation couldn’t be completed. Unable to locate a Java Runtime.
1.3 Deinstall Java use brew. In case that the output of step 1.1 shows the version of Java and the output contains information about Homebrew (e.g. “OpenJDK Runtime Environment Homebrew”), you can deinstall Java use brew, then go to step 2 “Install OpenJDK 11 via brew”.
# In case the openjdk 8 was found via "java -version"
brew uninstall openjdk@81.4 Deinstall Java manuelly
If the output of step 1.1 doesn’t contain Information about Homebrew, please then execute command below.
/usr/libexec/java_home -V
If the output contains information about JavaVirtualMachines, then you need to delete the folder inside JavaVirtualMachines like the example followed.
Output:
Matching Java Virtual Machines (2):
17.0.3 (x86_64) “Amazon.com Inc.” — “Amazon Corretto 17” /Users/yourUserName/Library/Java/JavaVirtualMachines/corretto-17.0.3/Contents/Home
1.8.0_275 (x86_64) “AdoptOpenJDK” — “OpenJDK 8” /Users/yourUserName/Library/Java/JavaVirtualMachines/adopt-openjdk-1.8.0_275/Contents/Home
# Delete the folder inside JavaVirtualMachines
cd /Users/yourUserName/Library/Java/JavaVirtualMachines/
ls
#Remove all subfolder under your JavaVirtualMachines folder.
sudo rm -fr /Users/yourUserName/Library/Java/JavaVirtualMachines/adopt-openjdk-1.8.0_275
sudo rm -fr /Users/yourUserName/Library/Java/JavaVirtualMachines/corretto-17.0.31.5 Further Option
If output of step 1.4 doesn’t contains Information about JavaVirtualMachines, you might also need to check if there are folder inside path /Library/Java/JavaVirtualMachines. In case there are any folder there, please use command below to remove them.
sudo rm -fr /Library/Java/JavaVirtualMachines/*1.6 Verify jdk is removed.
Run this command and none jdk should be found.
java -version
The output should be something like this:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
2. Install OpenJDK11 via brew
2.1 Install brew on mac OS. You can find details on their official website.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"2.2 Install OpenJDK 11
This step might take a few minutes.
brew install openjdk@11
3. Symlink JDK and check JDK version
3.1 Check the related info of installed openjdk 11.
brew search java
The output might be following:
==> Formulae
app-engine-java java-service-wrapper javarepl pdftk-java
google-java-format java11 ✔ jslint4java
java javacc libreadline-java
3.2 Show related information of installed java 11
brew info java11
The the Output might be:
……
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have openjdk@11 first in your PATH, run:
echo ‘export PATH=”/usr/local/opt/openjdk@11/bin:$PATH”’ >> ~/.zshrc
……
3.3 Symlink the OpenJDK11
Use the information from step 3.2 and execute the command suggested before:
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk3.4 Check Java version
java -version
The output should be like this:
openjdk version “11.0.17” 2022–10–18
OpenJDK Runtime Environment Homebrew (build 11.0.17+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.17+0, mixed mode)
Great! It’s done.
Please also keep in mind, there are also different ways to make it work, like use unzipped OpenJDK, directly compile the source or use docker etc.
4. What’s Next
Following posts from mine are also related to Java, these might be the next jounery for you:
More articles can be found here:
I hope you enjoyed today’s content.
You are welcome to my network:
Follow me on Medium
Your claps 👏 keep me continue writing high-quality articles. Thank you!






