How to set Java Home environment variable on Mac OS X

Here I’ll explain how to add JAVA_HOME variable on your MacBook (Mac OS).

Set JAVA_HOME in .bash_profile

Open Launchpad and search for Terminal and launch it.

Edit ~/.bash_profile:

and add to the end:

${/usr/libexec/java_home} is a symlink for current Java.

Press Ctrl+X to exit and “Y” to save your changes.

Now we need to recompile .bash_profile to apply changes:

Mac OS also allows you to edit ~/.profile instead of ~/.bash_profile.

How to check if JAVA_HOME on Mac?

Type “echo $JAVA_HOME” command to check Java Home environment variable on Mac OS X.

Success result should look like this:

Scroll Up