set a Java_home variable in Windows and Mac

To set a Java_Home variable in both Windows and macOS, follow the instructions below:

Windows

  1. Right-click on the Start button and search System or System Properties in the search bar.
    NexusPie Image
  2. Open System Properties and click on the Advanced System settings link on the left-hand side.
    NexusPie Image
  3. In the System Properties dialog, click on the Environment Variables button.NexusPie Image
  4. In the Environment Variables dialog, under the System Variables section, click on the New button.
    NexusPie-Image
  5. Enter JAVA_HOME the variable name.
  6. Enter the path to your JDK installation directory (e.g., C:\Program Files\Java\jdk1.x.x_xx) as the variable value.
  7. Click OK to save the changes.

macOS

  1. Open the Terminal application. You can find it by going to Applications > Utilities > Terminal.
  2. Enter the following command to determine the path to your JDK installation directory:bashCopy code/usr/libexec/java_home
  3. 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).
  4. In the Terminal, open your shell configuration file. For the bash shell, you can use the following command:bashCopy codenano ~/.bash_profile If you’re using a different shell (e.g., zsh), use the corresponding file (e.g., ~/.zshrc).
  5. In the opened file, add the following line:bashCopy codeexport JAVA_HOME=/path/to/your/JDK/installation/directory Replace /path/to/your/JDK/installation/directory with the path obtained in step 3.
  6. Press Ctrl + X to exit the editor, and then press Y to save the changes.
  7. 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.

Leave a Comment