1. What is Java Home
Many Java applications need to know the location of a
$JAVA_HOME directory. The
$JAVA_HOME on Mac OS X should be found using the
/usr/libexec/java_home command-line tool on Mac OS X 10.5 or later. On older Mac OS X versions where the tool does not exist, use the fixed path "
/usr/libexec/java_home tool dynamically finds the top Java version specified in Java Preferences for the current user. This path allows access to the
bin subdirectory where command-line tools such as
javac, etc. exist as on other platforms. The tool
/usr/libexec/java_home allows you to specify a particular CPU architecture and Java platform version when locating a
Another advantage of dynamically finding this path, as opposed to hardcoding the fixed endpoint, is that it is updated when a new version of Java is downloaded via Software Update or installed with a newer version of Mac OS X. For this reason, it is important that developers do not install files in the JDKs inside of
/System, since the changes will be lost with subsequent updates by newer versions of Java.
To obtain the path to the currently executing
$JAVA_HOME, use the
java.home System property.
Some applications use Java Home:
2. Bash or Zsh?
- For bash shell, we can put the environment variables at
- For zsh shell, we can put the environment variables at
2.1 Open Terminal and run:
/usr/libexec/java_home to get default JDK location.
If you do not see any SDK, please install by 2 ways:
- Download here: https://www.oracle.com/java/technologies/javase-downloads.html
- Install by brew:
brew install --cask adoptopenjdk/openjdk/adoptopenjdk8
2.2 Find all installed JDKs: