Install Java 8 on macOS with Homebrew


1. Download and install homebrew (if not installed already)

~ $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

~ $ which brew
/usr/local/bin/brew

~ $ brew update

2.  Download and install java 8

~ $ brew tap homebrew/cask-versions

~ $ brew cask install homebrew/cask-versions/adoptopenjdk8

~ $ java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)

OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)

3. Set up JAVA_HOME in .bashrc or /etc/profile

~ $ sudo vi /etc/profile

#add 2 following lines at the end of the file

export JAVA_HOME=`/usr/libexec/java_home -d 64 -v "1.8*"`


launchctl setenv JAVA_HOME `/usr/libexec/java_home -d 64 -v "1.8*"`

~ $ source /etc/profile

~ $ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home


References

Homebrew

AdoptOpenJDK

Comments