새소식

Framework/🍃 Spring

How to solved Neither the JAVA_HOME nor the JRE_HOME enviroment variable is defined?

728x90

To resolve the issue where neither the JAVA_HOME nor the JRE_HOME environment variable is defined, you need to set these environment variables to point to your Java Development Kit (JDK) or Java Runtime Environment (JRE) installation directories. Here’s how you can do it on different operating systems:

On Windows

  1. Find the JDK/JRE Installation Path:
    • Locate your JDK or JRE installation directory. By default, it might be something like C:\Program Files\Java\jdk-<version> or C:\Program Files\Java\jre-<version>.
  2. Set Environment Variables:
    • Open the Control Panel.
    • Go to System and Security > System.
    • Click on Advanced system settings.
    • In the System Properties window, click on the Environment Variables button.
  3. Add JAVA_HOME:
    • In the Environment Variables window, click on New under the System variables section.
    • Enter JAVA_HOME as the variable name and the path to your JDK installation directory as the variable value (e.g., C:\Program Files\Java\jdk-<version>).
  4. Add JRE_HOME (if needed):
    • Similarly, click on New under the System variables section.
    • Enter JRE_HOME as the variable name and the path to your JRE installation directory as the variable value (e.g., C:\Program Files\Java\jre-<version>).
  5. Update Path Variable:
    • Find the Path variable in the System variables section and select it.
    • Click Edit, then New, and add %JAVA_HOME%\bin.
    • Click OK to save the changes.
  6. Verify Setup:
    • Open a new command prompt and run echo %JAVA_HOME% and echo %JRE_HOME% to ensure the variables are set correctly.
    • Run java -version to verify that Java is correctly set up.

On macOS/Linux

  1. Find the JDK/JRE Installation Path:
    • Locate your JDK or JRE installation directory. This might be /Library/Java/JavaVirtualMachines/jdk-<version>/Contents/Home on macOS or /usr/lib/jvm/java-<version> on Linux.
  2. Set Environment Variables:
    • Open a terminal.
  3. Set JAVA_HOME and JRE_HOME:
    • Edit your shell configuration file (~/.bashrc, ~/.bash_profile, ~/.zshrc, or ~/.profile depending on your shell and system configuration).
  4. Add the Following Lines:
    • Replace /path/to/your/jdk and /path/to/your/jre with the actual paths to your JDK and JRE installation directories.
  5. sh
    Copy code
    export JAVA_HOME=/path/to/your/jdk export JRE_HOME=/path/to/your/jre export PATH=$PATH:$JAVA_HOME/bin
  6. Apply the Changes:
    • Run source ~/.bashrc or the relevant configuration file to apply the changes.
  7. Verify Setup:
    • Run echo $JAVA_HOME and echo $JRE_HOME to ensure the variables are set correctly.
    • Run java -version to verify that Java is correctly set up.

By following these steps, you should be able to define and set the JAVA_HOME and JRE_HOME environment variables properly, resolving the issue.

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.