To set the JAVA_HOME
environment variable in macOS, follow these steps:
bash_profile
file in a text editor:nano ~/.bash_profile
/path/to/java
with the path to the Java installation directory:export JAVA_HOME=/path/to/java
Press Ctrl + O
to save the file and Ctrl + X
to exit the text editor.
Reload the bash_profile
file by typing the following command:
source ~/.bash_profile
JAVA_HOME
environment variable has been set correctly, type the following command:echo $JAVA_HOME
This should print the path to the Java installation directory that you set in the bash_profile
file.
Note: The bash_profile
file is a hidden file in your home directory that is executed every time you start a new Terminal session. You can use the bash_profile
file to set environment variables, such as JAVA_HOME
, that you want to be available every time you start a new Terminal session.