Where is JAVA_HOME on macOS Mojave (10.14) to Lion (10.7)?
On macOS, the JAVA_HOME environment variable is typically set in the /etc/launchd.conf file.
On macOS, the JAVA_HOME environment variable is typically set in your shell profile file. The /etc/launchd.conf method has been deprecated since macOS 10.10 and should not be used.
To set the JAVA_HOME variable on macOS Mojave (10.14) or later, follow these steps:
- Open the Terminal application.
- Run the following command to determine the path to your JDK installation:
/usr/libexec/java_homeThis command will output the path to the current JDK installation, such as /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home.
- Run the following command to open your shell profile (
~/.zshrc) in a text editor:
nano ~/.zshrc- Add the following line to the file:
export JAVA_HOME=$(/usr/libexec/java_home)- Save the file and exit the text editor.
- Run the following command to apply the changes:
source ~/.zshrcYou should now be able to use the JAVA_HOME environment variable in your terminal sessions.
On macOS Lion (10.7) or earlier, the JAVA_HOME variable is typically set in the ~/.bash_profile file. To set the JAVA_HOME variable on these versions of macOS, follow these steps:
- Open the Terminal application.
- Run the following command to determine the path to your JDK installation:
/usr/libexec/java_homeThis command will output the path to the current JDK installation.
- Run the following command to open your shell profile in a text editor:
nano ~/.bash_profile- Add the following line to the file:
export JAVA_HOME=$(/usr/libexec/java_home)- Save the file and exit the text editor.
- Run the following command to apply the changes:
source ~/.bash_profile