macOS: JAVA_HOME environment Setup

<h1>1. What is Java Home</h1> <p>Many Java applications need to know the location of a&nbsp;<code>$JAVA_HOME</code>&nbsp;directory. The&nbsp;<code>$JAVA_HOME</code>&nbsp;on Mac OS X should be found using the&nbsp;<code>/usr/libexec/java_home</code>&nbsp;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 &quot;<code>/Library/Java/Home</code>&quot;. The&nbsp;<code>/usr/libexec/java_home</code>&nbsp;tool dynamically finds the top Java version specified in Java Preferences for the current user. This path allows access to the&nbsp;<code>bin</code>&nbsp;subdirectory where command-line tools such as&nbsp;<code>java</code>,&nbsp;<code>javac</code>, etc. exist as on other platforms. The tool&nbsp;<code>/usr/libexec/java_home</code>&nbsp;allows you to specify a particular CPU architecture and Java platform version when locating a&nbsp;<code>$JAVA_HOME</code>.</p> <p>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&nbsp;<code>/System</code>, since the changes will be lost with subsequent updates by newer versions of Java.</p> <p><a href="https://nphausg.medium.com/macos-java-home-environment-setup-51961ea27347"><strong>Read More</strong></a></p>