How To Java Home Path In Linux

In this guide, we will demonstrate how to set the JAVA_HOME path in Linux. This is a common requirement for developers who often need to set the Java environment variables to point to the installed Java directories.


Before proceeding with the steps in this tutorial, make sure you have the following:

  • Java installed on your Linux system. If you haven’t installed it yet, check out our guide on how to install Java on Linux.
  • Access to a terminal window/command line (Ctrl-Alt-T)

Step 1: Find Your Java Installation Directory

The first step is to find where Java is installed. You can do this by using the update-alternatives command:

  $ update-alternatives --config java

This command will show a list of all installed Java versions and their paths.

Step 2: Set JAVA_HOME Environment Variable

Now that you’ve located your Java installation directory, it’s time to set the JAVA_HOME environment variable. You can do this by editing the /etc/environment file with a text editor of your choice. In this guide, we will use nano:

  $ sudo nano /etc/environment

In this file, add the following line at the end:


Please note to replace /usr/lib/jvm/java-11-openjdk-amd64 with the path of your Java installation directory.

Step 3: Reload System-Wide Environment Variables

Now that you’ve set the JAVA_HOME environment variable, save the changes and reload the system-wide environment variables with the following command:

  $ source /etc/environment

Step 4: Verify the Setup

Finally, validate whether the JAVA_HOME environment variable has been set correctly by running the following command:

  $ echo $JAVA_HOME

This should display the path to your Java installation directory.

That’s it! You’ve successfully set the JAVA_HOME path in Linux. This will make it easier for you to manage your Java-based applications and tools on your system.