Setup Java_Home Path on Debian 11

Setup Java_Home Path on Debian 11 is very simple and you only need to pay attention to a few points that are fully mentioned in this article.

To compile and run Java applications successfully you’ll need to set up the JAVA_HOME and PATH environment variables. 

The PATH environment variable consists of a list of directories containing executable programs on your system. So for easy access to a program, you need to add the directory that contains it to the PATH.

The JAVA_HOME environment variable is set to the JDK installation directory. The variable can then be used by any program that needs access to the JDK.

You can think of JAVA_HOME as a pointer. Any time you start a program that relies on the JDK in some way, the program uses that pointer to find it.

Setup Java_Home Path on Debian 11 and Path Environment

To complete and Set up Java_Home Path on Debian 11, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Debian 11.

Install OpenJDK on Debian 11

To set up your Java_Home and Path variables, you need to have OpenJDK installed on your server.

First, use the following command to update your local package index:

sudo apt update

Then, run the command below to install OpenJDK on your server:

sudo apt install openjdk-17-jdk

Set Java_Home Environment Variable on Debian 11

At this point, you need to find the installation path of OpenJDK on your system. Usually, it is in the /usr/lib/jvm/java-17-openjdk-amd64/.

To set the JAVA_HOME environment path, enter the following command:

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

Then, you can verify it by using the command below:

echo $JAVA_HOME
Output
/usr/lib/jvm/java-17-openjdk-amd64

Note: If JAVA_HOME isn’t set then programs that rely on it might not be able to locate the JDK. In the worst-case scenario, this will stop the program from executing. 

Add the JAVA bin directory to the PATH variable

Similar to the JAVA_HOME path, you need to add the $PATH variable as well on Debian 11. To do this, run the command below:

export PATH=$PATH:$JAVA_HOME/bin

You can verify it by using the command below:

echo $PATH
Output
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-17-openjdk-amd64/bin

After setup Java_Home path on Debian 11 you need to verify the setup, you can verify your Java installation on Debian 11 by using the command below:

java -version
Output
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment (build 17.0.4+8-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 17.0.4+8-Debian-1deb11u1, mixed mode, sharing)

That’s it you are done. From here you can easily develop and run JAVA applications on your system.

Conclusion

At this point, you have learned to Setup Java_Home Path on Debian 11.

Hope you enjoy it.

You may like these articles:

Fix “apt-add-repository” Command Not Found on Debian 11

Install and Configure Caddy on Debian 11

How To Install VirtualBox on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

One comment

Leave a Reply

Stay informed and not overwhelmed, subscribe now!