To set a Java_Home variable in both Windows and macOS, follow the instructions below:
Windows
- Right-click on the Start button and search System or System Properties in the search bar.
- Open System Properties and click on the Advanced System settings link on the left-hand side.
- In the System Properties dialog, click on the Environment Variables button.
- In the Environment Variables dialog, under the System Variables section, click on the New button.
- Enter
JAVA_HOME
the variable name. - Enter the path to your JDK installation directory (e.g.,
C:\Program Files\Java\jdk1.x.x_xx
) as the variable value. - Click OK to save the changes.
macOS
- Open the Terminal application. You can find it by going to Applications > Utilities > Terminal.
- Enter the following command to determine the path to your JDK installation directory:bashCopy code
/usr/libexec/java_home
- Copy the output of the command, which will be the path to your JDK installation directory (e.g.,
/Library/Java/JavaVirtualMachines/jdk1.x.x_xx.jdk/Contents/Home
). - In the Terminal, open your shell configuration file. For the bash shell, you can use the following command:bashCopy code
nano ~/.bash_profile
If you’re using a different shell (e.g., zsh), use the corresponding file (e.g.,~/.zshrc
). - In the opened file, add the following line:bashCopy code
export JAVA_HOME=/path/to/your/JDK/installation/directory
Replace/path/to/your/JDK/installation/directory
with the path obtained in step 3. - Press Ctrl + X to exit the editor, and then press Y to save the changes.
- Restart the Terminal for the changes to take effect.
After following these steps, the JAVA_HOME
environment variable should be set to the specified JDK installation directory on both Windows and macOS.