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 setup 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 setup the JAVA_HOME and PATH variables.

We have run the commands and procedure mentioned in this article on a Debian 10 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-8-jdk

When prompted for the password, enter the sudo password.

Install OpenJDK

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

If you receive this error during installation: “Package OpenJDK has no installation candidate”, follow the below steps:

1. Edit the sources.list file by using the following command in Terminal:

$ sudo nano /etc/apt/sources.list

2. Add the following repository to your sources.list file.

deb sid main

Then hit Ctrl+O and Ctrl+X to save and exit the file.

Update sources.list file

3. Update the repository index using the following command:

$ sudo apt update

4. Then run the installation command as follows:

$ sudo apt install openjdk-8-jdk


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

$ export JAVA_HOME=/usr/lib/jvm/java-8-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 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 setup bin directory location.

Enter this command in Terminal to add 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 setup 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 setup the JAVA_HOME variable in your Debian OS. Now you can easily develop and run JAVA applications on your system.

How to setup the JAVA_HOME path in Debian 10

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn