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.

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 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 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 3 Check the JAVA setting

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

4.1 ★ | 48 Vote

May be interested

  • How to install Microsoft Teams on LinuxPhoto of How to install Microsoft Teams on Linux
    if your job requires using a linux distribution such as ubuntu, debian or red hat, you no longer need to use a windows 10 device to connect with colleagues, as microsoft teams is now available on linux. .
  • How to install dictionaries in Linux TerminalPhoto of How to install dictionaries in Linux Terminal
    a locally stored dictionary utility can really be useful when no other dictionary is available. there are many options in the linux software world. among these, there is an option that runs fairly 'smoothly' from the system terminal, called sdcv.
  • How to change the cursor size on the Debian 10 desktopPhoto of How to change the cursor size on the Debian 10 desktop
    debian allows you to change the cursor size via the settings utility. you can access the settings utility through the application launcher search.
  • How to spell check in Linux TerminalPhoto of How to spell check in Linux Terminal
    linux also has a command line spell checker utility in terminal. the utility is called aspell and is installed by default on ubuntu. this is how you can use aspell to check spelling in a terminal.
  • How to install Safari on LinuxPhoto of How to install Safari on Linux
    there are two potential workarounds to install safari on linux: use yourself wine or wine in combination with playonlinux (provide graphical user interface (ui) for wine).
  • How to reset the password for sudo in DebianPhoto of How to reset the password for sudo in Debian
    the user password is changed in debian using the passwd command. in this article, tipsmake.com will explain how root users can change their own passwords on debian servers.