How to Install Java on Mac OS
Installing Java on MacOS
We will install OpenJDK which is free and doesn't need Oracle JDK licence.
Go to https://jdk.java.net/19/ and search for the JDK version.
Download the tar file using command below
$ wget https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_macos-x64_bin.tar.gz
Untar the file and move the folder to Mac OS Java location
$ tar -xvf openjdk-19.0.2_macos-x64_bin.tar.gz
$ sudo mv jdk-19.0.2.jdk /Library/Java/JavaVirtualMachines/
Set environment variable to be able to use java from any location by adding the following to .bash_profile
$ vi $HOME/.bash_profile
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-19.0.2.jdk/Contents/Home"
PATH="${JAVA_HOME}/bin:${PATH}"
export PATH
Restart the shell or source the bash_profile
Comments