Skip to content

Instantly share code, notes, and snippets.

@fscm
Last active March 16, 2022 18:04
Show Gist options
  • Save fscm/b689f0a82f7e16242e200c1485c4fab1 to your computer and use it in GitHub Desktop.
Save fscm/b689f0a82f7e16242e200c1485c4fab1 to your computer and use it in GitHub Desktop.
[macOS] Install OpenJDK

[macOS] Install OpenJDK

Instructions on how to install OpenJDK on macOS.

Uninstall

First step should be to unsinstall any previous OpenJDK installation. This step can be skipped if no OpenJDK version was previously installed.

To uninstall any previous OpenJDK installations use the following commands:

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-*.jdk

Install

OpenJDK can be obtained here (or here for older versions). Copy the link for the version that you want to install from there.

Get the OpenJDK archive and extract it with the following command:

curl --silent --location --retry 3 "https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_macos-x64_bin.tar.gz" | sudo tar xz --no-same-owner -C /Library/Java/JavaVirtualMachines/

Configure

Add the following line to the .bash_profile file:

export JAVA_HOME=$(/usr/libexec/java_home 2>/dev/null)

Verify

Open a new terminal window and check if java is installed:

java -version
javac -version

Also check if the JAVA_HOME environment variable was defined using the following command:

echo $JAVA_HOME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment