Instructions on how to install OpenJDK on macOS.
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
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/
Add the following line to the .bash_profile
file:
export JAVA_HOME=$(/usr/libexec/java_home 2>/dev/null)
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