How to set up the JAVA_HOME path in Debian 10

s2 0

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

This article will show you how to install Java JDK on Debian OS and then set up the JAVA_HOME and PATH variables.

We ran the commands and procedures mentioned in this article on a Debian 10 system. The same procedure can be followed in other Linux distributions and older versions of Debian.

Let’s start by installing JDK.

Install OpenJDK on Debian

First start the terminal in your operating system. Go to the Activities tab in the top left corner of your desktop. Then search for the Terminal application by entering the appropriate keyword in the search bar. In the results, click the Terminal icon to open it.

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

$ sudo apt install openjdk-8-jdk

When prompted for the password, enter the sudo password.

The system may request confirmation by providing the Y / n option. Press y then Enter to confirm, which will start the installation of Open JDK on your system.

If you get this error during installation: “Package OpenJDK has no candidate for installation”, try the following steps:

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

$ sudo nano /etc/apt/sources.list

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

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

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

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

Define the JAVA_HOME path

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

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

Set JAVA_HOME

After setting 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 shown in the following screenshot.

Check JAVA_HOME

Add the JAVA bin directory to the PATH variable

Similar to the JAVA_HOME path, we now also add the $ PATH variable. The $ PATH variable points to the bin directory under the JDK installation directory. Since the location of the JDK directory has already been set up with the JAVA_HOME variable, we can now simply use the JAVA_HOME attribute to set up the location of the bin directory.

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

$ export PATH=$PATH:$JAVA_HOME/bin

Add the JAVA bin directory to the PATH variable

The Java bin directory is appended to the existing PATH variable. Run the following command in Terminal to check:

$ echo $PATH

Display the content of the PATH variable

Test the JAVA setup

Now we’ve installed OpenJDK and set up the JAVA_HOME and PATH variables. Now is the time to check the installation. To do this, run the following command in the terminal:

$ java -version

Test the JAVA setup

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

How to set up the JAVA_HOME path in Debian 10