W3docs

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:

  1. Open the Terminal application.
  2. Run the following command to determine the path to your JDK installation:
/usr/libexec/java_home

This command will output the path to the current JDK installation, such as /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home.

  1. Run the following command to open your shell profile (~/.zshrc) in a text editor:
nano ~/.zshrc
  1. Add the following line to the file:
export JAVA_HOME=$(/usr/libexec/java_home)
  1. Save the file and exit the text editor.
  2. Run the following command to apply the changes:
source ~/.zshrc

You 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:

  1. Open the Terminal application.
  2. Run the following command to determine the path to your JDK installation:
/usr/libexec/java_home

This command will output the path to the current JDK installation.

  1. Run the following command to open your shell profile in a text editor:
nano ~/.bash_profile
  1. Add the following line to the file:
export JAVA_HOME=$(/usr/libexec/java_home)
  1. Save the file and exit the text editor.
  2. Run the following command to apply the changes:
source ~/.bash_profile