In this guide, we want to teach you How To Set up Java_Home and Path Environment Variables on Debian 11.
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.
Set up Java_Home and Path Environment Variables on Debian 11
To complete this guide, 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:
Then, you can verify it by using the command below:
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 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:
You can verify it by using the command below:
Also, you can verify your Java installation on Debian 11 by using the command below:
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.
At this point, you have learned to Set up Java_Home and Path Environment Variables on Debian 11.
Hope you enjoy it.
You may be like these articles:
Fix “apt-add-repository” Command Not Found on Debian 11
Install and Configure Caddy on Debian 11