How to set the JAVA_HOME path in Debian 10

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

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

Note : The commands and procedures mentioned in this article are done on Debian 10. The same procedure can be applied in other Linux distributions and on older versions of Debian.

Let's start by installing JDK first.

Install OpenJDK on Debian

First, launch Terminal in the operating system. Go to the Activities tab in the top left corner of the desktop. Then search for the Terminal application by typing the relevant keyword into the search bar. From the result, click the Terminal icon to open.

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

 $ sudo apt install openjdk-8-jdk 

When prompted for a password, enter the sudo password.

How to set the JAVA_HOME path in Debian 10 Picture 1How to set the JAVA_HOME path in Debian 10 Picture 1 Install OpenJDK on Debian

The system may require confirmation by providing the Y / N option. Press Y and Enter to confirm, then the Open JDK installation process will be started on the system.

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

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

 $ sudo nano /etc/apt/sources.list 

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

 deb http://ftp.de.debian.org/debian sid main 

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

3. Update the repository index with the following command:

 $ sudo apt update 

4. Then run the installation command as follows:

 $ sudo apt install openjdk-8-jdk 

Set the path for JAVA_HOME

Find the path to install OpenJDK on the 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 

You have now set the JAVA_HOME path and 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 shown in the following screenshot.

How to set the JAVA_HOME path in Debian 10 Picture 2How to set the JAVA_HOME path in Debian 10 Picture 2 The value is stored in the JAVA_HOME variable

Add the JAVA bin directory to the PATH variable

Similar to the JAVA_HOME path, you will now add the $ PATH variable. The $ PATH variable points to the bin directory in the JDK installation directory. Since the JDK directory location has been set using the JAVA_HOME variable, now we only need to use the JAVA_HOME attribute to set the bin directory location.

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

 $ export PATH=$PATH:$JAVA_HOME/bin 

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

 $ echo $PATH 

Check the JAVA setting

Now that we've installed OpenJDK and set the variables JAVA_HOME and PATH, it's time to verify the installation. In Terminal, run the following command to do so:

 $ java -version 
How to set the JAVA_HOME path in Debian 10 Picture 3How to set the JAVA_HOME path in Debian 10 Picture 3 Check the JAVA setting

Now, you can easily develop and run JAVA applications on your system.

4.1 ★ | 48 Vote