In this tutorial, I will show you how to install OpenJDK 11 Mac. You have to pay for Oracle JDK so it’s better to use OpenJDK.
OpenJDK (Open Java Development Kit) is a free and open-source implementation of the Java Platform, Standard Edition (Java SE).[1] It is the result of an effort Sun Microsystems began in 2006. The implementation is licensed under the GNU General Public License (GNU GPL) version 2 with a linking exception. Were it not for the GPL linking exception, components that linked to the Java class library would be subject to the terms of the GPL license.
Requirements
- brew should be installed (https://brew.sh/)
Read Also: How to install Java 8 on Ubuntu 18.04
Read Also: How to install Java 8 on Debian
Read Also: How to install Java 10 on Mac using brew
1. Brew tap
First of all, we need to tap a brew repo. Execute the following command:
$ brew tap AdoptOpenJDK/openjdk
The above will add more repositories to brew.
Read Also: How to uninstall/remove Java 10 from Mac
2. Install OpenJDK 11 Mac
After adding tap, let’s install OpenJDK using brew.
$ brew cask install adoptopenjdk11
Or on newer version
$ brew install --cask adoptopenjdk11
So, now we have installed Java 11, we can check the installation with the following command.
3. Check JDK Version
Now we can check the JDK version.
# java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.2+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.2+9, mixed mode)
Now Java has installed properly.
4. Java Location
Now let’s check the java path.
# which java
/usr/bin/java
Please let me know how you liked the tutorial.
If you like this tutorial please consider buying me a coffee!
Chetan thank you for this useful directions.
In my case because of access restriction I got this error:
Error: Permission denied @ dir_s_mkdir – /usr/local/Caskroom/adoptopenjdk11/11.0.4,11
Next command resolved issue:
sudo chown -R $(whoami) /usr/local/Caskroom/adoptopenjdk11
Hey Vasyl,
Cool, Thanks for the solution.
You need to explain what to do next if “java -version” shows an old version.
Hey Michael,
Thanks for reaching out. If the
java -version
shows the old version that means the new version is not installed properly. brew automatically adds the new version to the path.Alternatively, you can find where new version is installed and link it to the /usr/bin/java like this:
sudo ln -s /path/of/java /usr/bin/java
You can find java using locate or find command also.
For users of MAC with ARM, you’ll want to prepend arch -arch x86_64 so, you’d run:
“`
arch -arch x86_64 brew tap AdoptOpenJDK/openjdk
“`
He doesn’t really need to. He is doing you a favour already, explaining everything else. This is the problem with our industry. People like you who feel entitled for everything.