If I have Oracle Java SE JDK 8 installed on my mac, how can I upgrade to Open JDK 8 and be sure it will be used by default?
Motivation: Android build tools seem to need JDK 8, but according to the following links Oracle JDK 8 will not receive free updates after January 2019 for commercial use, not even security updates:
Best Answer
Recommended prerequisite: check which versions of Java may already be installed using the following command:
/usr/libexec/java_home -V
The following commands worked for me:
brew search openjdk
# check if desiredadoptopenjdk8
cask may already availablebrew search java
# (optional)brew tap AdoptOpenJDK/openjdk
# (assuming that the desiredadoptopenjdk8
cask is not already available)brew search openjdk
# check that the desiredadoptopenjdk8
cask is now availablebrew install --cask adoptopenjdk8
Then the following commands confirmed that I was using the desired OpenJDK 8 version by default (with no
JAVA_HOME
environment variable setting):java -version
javac -version
And the following commands confirmed that I have both Java SE 8 and OpenJDK 8 installed:
/usr/libexec/java_home -V
ls /Library/Java/JavaVirtualMachines
Note that
which java
andwhich javac
show thatjava
andjavac
are still run from/usr/bin
.Followup step: remove the old Java SE SDK from
/Library/Java/JavaVirtualMachines
, as documented in: https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html#A1096903AdoptOpenJDK 8 package notes May 2019:
adoptopenjdk8
was also added tohomebrew/cask-versions
, and this led to some issues: https://github.com/AdoptOpenJDK/homebrew-openjdk/issues/106There is now a proposal to rename
adoptopenjdk8
toopenjdk8
inhomebrew/cask-versions
: https://github.com/Homebrew/homebrew-cask-versions/pull/7375If this proposal is merged, this answer will likely be updated to recommend installing the renamed cask.
See also (some references):