Migrating from Oracle JDK to OpenJDK on Mac

Solomon Mark
3 min readMay 6, 2019

--

Oracle has announced that the Oracle JDK 8 builds released after JAN 2019 will not be free for commercial use. An alternate for Oracle JDK is OpenJDK. OpenJDK is a free and open-source implementation of the Java Platform Standard Edition. In this Article we are going to remove Oracle JDK and install OpenJDK.

UnInstalling Oracle JDK from Mac:

Navigate to following directory in finder.

cd /Library/Java/JavaVirtualMachines/

Remove all Installed JDKs from above directory by executing following command. Note: Beware while removing any file using rm -rf command in mac terminal.

sudo rm -rf jdk1.8.0_71.jdk

Here, we are removing jdk1.8.0 as a admin user. Later check Java runtime in terminal by running following command.

java -version

You should see following message in terminal. “No Java runtime present, requesting install.”

Installing OpenJDK in Mac:

I am using Homebrew to install OpenJDK in my Mac. You can download OpenJDK binaries from jdk.java.net and extract in /Library/Java/JavaVirtualMachines/.

If you don’t have Homebrew you can install by executing following command:

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Installing homebrew in mac

Now we can use brew to install openJDK. Following command clones adoptopenjdk to your Mac. Adoptopenjdk is a Prebuilt OpenJDK Binaries for Free.

brew tap AdoptOpenJDK/openjdk

cloning AdoptOpenJDK

Brew search commands finds all available versions to install from AdoptOpenJDK.

brew search /adoptopenjdk/

brew search result from adoptopenJdk

The Casks section contains the identifiers for the various JDK versions.To install a specific JDK version we can execute following command. brew cask install <identifier>. For installing adoptopenjdk8 execute following command.

brew install cask adoptopenjdk8

Installing AdoptOpenJDK8

Now, Set up JAVA_HOME in bash_profile file. Execute following command to open bash_profile file for editing.

nano ~/.bash_profile

And add following line in bash_profile file. export JAVA_HOME=$(/usr/libexec/java_home). Save and close the file.

Now when you execute java -version to check JDK version it should show OpenJDK runtime Environment.

Checking java version

That’s it. Now we have successful removed Oracle JDK and Installed OpenJDK in our Mac. If you found any other easy way to install OpenJDK in Mac feel free to share in comments. Thanks :)

--

--