How to setup the JAVA_HOME path in Debian 11

JAVA_HOME Path in Debian Linux

Java is a very popular programming language that is used in desktop software development, mobile applications, business applications, and so on. It requires the installation of the Java Runtime Environment (JRE) and Java Development Kit (JDK) in order to develop and run Java applications. After installation of JRE and JDK, you also need to set up JAVA_HOME in order for many java based applications to work properly. JAVA_HOME is basically an OS environment variable that points to the directory where the JDK or JRE is installed on your system. It needs to be configured in all OSs with Java installed such as Linux, Windows, and macOS.

In this article, we will learn how to install Java JDK on Debian OS and then set up the JAVA_HOME and PATH variables.

We have run the commands and procedure mentioned in this article on a Debian 11 system. The same procedure can be followed in other Linux distributions and older versions of Debian as well.

Let’s start by installing JDK first.

Install OpenJDK on Debian

First, launch the Terminal in your OS. Go to the Activities tab in the top left corner of your desktop. Then search for the Terminal application by typing the relevant keyword in the search bar. From the results, click on the Terminal icon to open.

Now in the Terminal, run this command as sudo to install Open JDK.

$ sudo apt install openjdk-17-jdk

When prompted for the password, enter the sudo password.

Install Java OpenJDK

The system might ask for confirmation by providing the Y/n option. Hit y and then Enter to confirm, after which the installation of Open JDK will be started on your system.


Find out the installation path of OpenJDK on your system. Usually, it is /usr/lib/jvm/java-17-openjdk-amd64/. To set the JAVA_HOME environment path, enter the following command in Terminal:

$ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64


Now you have set the JAVA_HOME path, you can verify it by running the following command in Terminal:

$ echo $JAVA_HOME

In the output, you will see the value stored in the JAVA_HOME variable as displayed in the following screenshot.


Add the JAVA bin directory to the PATH variable

Similar to the JAVA_HOME path, we will now add the $PATH variable as well. $PATH variable points to the bin directory under the JDK installation directory. As the JDK directory location has already been set up using the JAVA_HOME variable, now we can just use the JAVA_HOME attribute to set up the bin directory location.

Enter this command in Terminal to add the Java bin directory to the PATH variable:

$ export PATH=$PATH:$JAVA_HOME/bin

Add JAVA bin directory to the PATH variable

Java bin directory will be appended to the existing PATH variable. To verify it, run the following command in Terminal:

$ echo $PATH

Show content of PATH Variable

Test JAVA setup

Now we have installed OpenJDK and set up the JAVA_HOME and PATH variables, now its time to verify the installation. In the Terminal, run the following command to do so:

$ java -version

Test the JAVA setup

So there you have it! In this article, you have learned how to set up the JAVA_HOME variable in your Debian OS. Now you can easily develop and run JAVA applications on your system.