Manually Install OpenJDK in OSX Mojave

Mindwatering Incorporated

Author: Tripp W Black

Created: 01/27 at 03:14 PM

 

Category:
OS X Tips & Hints
General Mac Tips

Task:
Replace the Oracle-branded Java with OpenJDK version (still Oracle maintained).


Notes:
- The later versions of Apple MacOS uses the /usr/libexec/java_home program to locate Java versions and do that pop-up to install the Oracle one after you de-installed the Oracle version.
To check, open a new Terminal window, and check:
$ /usr/libexec/java_home -V
After we are done this task, this command will output our new virtual machines.
Matching Java Virtual Machines (1):
13.0.2, x86_64: "OpenJDK 13.0.2" /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
- With MacOS, we can have more than one Java (JVM) installed. We just have to use the correct directory structure, as the directory path above.
- Specifically, we will be adding the Java program for "all users" by adding the Java/JVM to the main /Library/ folder structure instead of the current user ~/Library/ folder structure.
- At this writing, the OpenJDK version does not include the javaws and JLNP. They are installed separately (Hint: IcedTea project at jdk.java.net).


Prerequisite Steps:
If this Mac has never had a Java JVM installed, all the folder structure needs to be added.
Using the same terminal window, perform the following, as needed:
$ sudo su
< enter password>
# cd /Library/
Check if Java folder exists.
# ls Java
If no result, run # mkdir Java to create the folder.
# cd Java
# ls JavaVirtualMachines
If no result, run # mkdir JavaVirtualMachines to create the folder.
Our Java JVM will be added inside this folder. Exit root user.
# exit
Leave the Terminal window open or minimized.


Steps to Download and Install:
1. Using your web browser, visit the OpenJDK Downloads page at Java.Net:
https://jdk.java.net

Beside the Ready for use label, choose the current version:
e.g. JDK 13

2. On the JDK General-Availability Release page for this version of Java (e.g. JDK 13.0.2), under the Build "x" header, click the tar.gz macOS/x64 link.
e.g. openjdk-13.0.2_osx-x64_bin.tar.gz

3. Once downloaded, open the Downloads folder, locate the tar.gz file, and double-click to expand/decompress the archive.

The result will be a folder with the same version:
e.g. jdk-13.0.2.jdk

4. Leaving the Downloads Finder window open, open another Finder window via the Finder menu Go --> Go to folder. In the pop-up, enter /Library/Java/JavaVirtualMachines/ and click Go.
Note:
On one of our machines that never had a JVM (Java) installed, we didn't have a Java folder. We had to create the folder inside the Library folder.
If the JavaVirtualMachines folder does not exist create it.

5. Drag-drop the expanded folder, e.g. jdk-13.0.2.jdk from the Downloads Finder window into the JavaVirtualMachines Finder window.
Authenticate as prompted.
The JVM is now installed.


Validation:
Return to the Terminal window still open, enter the java_home command again, this time, we should see that the JVM is installed.
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
13.0.2, x86_64: "OpenJDK 13.0.2" /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home

The Java JVM is installed and ready.





previous page