Set JAVA_HOME Environment Variable on macOS X 10.6
Setting the JAVA_HOME environment variable is crucial for many Java applications that rely on shell scripts for environment configuration. In macOS X 10.6, several paths can be used for this variable, including:
These paths may link to the current Java Virtual Machine (JVM) defined in the Java Preference pane. The question arises which one to use or if any of them is acceptable.
The recommended solution is to set JAVA_HOME to the output of the /usr/libexec/java_home command, which retrieves the Java path specified in the Java preferences. This approach has proven to be reliable and issue-free.
export JAVA_HOME=$(/usr/libexec/java_home)
Occasionally, it may be necessary to override JAVA_HOME with an older Java version. For instance, if a program requires 32-bit Java 5, the following command can be used to set JAVA_HOME:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.5)
If /usr/libexec/java_home is not in the path, it can be added using:
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home
For additional information, refer to the Oracle documentation on the java_home command and the Spring Tool Suite article on configuring the JDK in macOS.
The above is the detailed content of How to Set the JAVA_HOME Environment Variable on macOS X 10.6?. For more information, please follow other related articles on the PHP Chinese website!