On this page
    
    Expanded Knowledge: JAVA_HOME
JAVA_HOME is an environment variable used to specify the location of the Java Development Kit (JDK) installation on your system. It plays a crucial role in various Java-based applications and tools by providing a central reference to the JDK’s installation directory. Here’s a detailed explanation of JAVA_HOME, its purpose, and how to set it up:
Purpose of JAVA_HOME 
- Central Reference: It allows applications to easily find the JDK without needing to specify the full path every time.
- Configuration: Many Java-based applications (like Apache Tomcat, Maven, Gradle) and build tools depend on the- JAVA_HOMEvariable to locate the Java compiler (javac) and runtime (java).
- Version Control: By setting- JAVA_HOME, you can control which version of Java your applications use, making it easier to switch between different JDK versions if needed.
How to Set JAVA_HOME 
The steps to set the JAVA_HOME variable vary slightly depending on the operating system you are using.
- 
Finding Your JDK Installation Path First, you need to find the path where the JDK is installed. It typically looks like this: - Windows:- C:\Program Files\Java\jdk-<version>
- Linux:- /usr/lib/jvm/java-<version>
- macOS:- /Library/Java/JavaVirtualMachines/jdk-<version>.jdk/Contents/Home
 
- 
Setting JAVA_HOME - On Windows:
 - Right-click on This PCorComputerand selectProperties.
- Click on Advanced system settings.
- Click on the Environment Variablesbutton.
- In the System variablessection, clickNew.
- Set the Variablename as JAVA_HOME and the Variable value as the path to your JDK (e.g.,C:\Program Files\Java\jdk-<version>).
- Click OK to save.
 - On Linux:
 - Open a terminal.
- Edit your profile configuration file (e.g., .bashrc, .bash_profile, or .profile depending on your shell) using a text editor:
 nano ~/.bashrc- Add the following line at the end of the file:
 export JAVA_HOME=/usr/lib/jvm/java-<version>- Save the file and run the following command to apply the changes:
 source ~/.bashrc- On macOS:
 - Open a terminal.
- Edit your profile configuration file (e.g., .bash_profile, .zshrc) using a text editor:
 nano ~/.bash_profile- Add the following line:
 export JAVA_HOME=$(/usr/libexec/java_home)- Save the file and run the following command to apply the changes:
 source ~/.bash_profile
Verifying JAVA_HOME 
To verify that JAVA_HOME has been set correctly:
- On Windows: Open a Command Prompt and type:
  echo %JAVA_HOME%
  
  - On Linux/macOS: Open a terminal and type:
  echo $JAVA_HOME
  
  If the path to your JDK installation is displayed, then JAVA_HOME is set correctly.