Solarian Programmer

My programming ramblings

Installing OpenJDK 11 on macOS Mojave

Posted on September 28, 2018 by Paul

Updated 25 February 2019

This is a short note about getting started with Java 11 on macOS. As you probably know, starting with Java 11 there was a big change in the license under which the official Oracle JDK is provided. In short, you need to buy a license from Oracle if you want to use the official JDK in a commercial setting. As far as I know, using Oracle’s JDK on your private computer for testing and learning purposes is allowed.

That being said, for most users OpenJDK is the new JDK of choice, it is provided under an open source license and you don’t need to pay for using it.

Start by getting OpenJDK, chose the macOS version. Extract the archive by double clicking on the file or, assuming it is in your Downloads folder, write this in your Terminal:

1 cd ~/Downloads
2 tar xf openjdk-11.0.2_osx-x64_bin.tar.gz

Next step, is to move the extracted folder to a place where macOS searches for Java JDK:

1 sudo mv jdk-11.0.2.jdk /Library/Java/JavaVirtualMachines/

Now, check if you’ve successfully installed the JDK with:

1 java -version
2 javac -version

This is what I see on my machine:

1 ~ $ java -version
2 openjdk version "11.0.2" 2019-01-15
3 OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
4 OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
5 ~ $ javac -version
6 javac 11.0.2
7 ~ $

Just to be sure, try to compile and run a simple program:

1 class HelloWorld {
2     public static void main(String[] args) {
3         System.out.println("Hello World!");
4     }
5 }

Save the above as and compile it with:

1 javac

If you want to run the compiled version:

1 java HelloWorld

This is what I see on my machine:

1 ~ $ javac
2 ~ $ java HelloWorld
3 Hello World!
4 ~ $

Show Comments