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.
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 the
/etc/launchd.conffile in a text editor:
sudo nano /etc/launchd.conf- Add the following line to the file, replacing
/path/to/jdkwith the path you obtained in step 2:
setenv JAVA_HOME /path/to/jdkSave the file and exit the text editor.
Run the following command to apply the changes:
launchctl setenv JAVA_HOME /path/to/jdkYou 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,