In this tutorial, we will show you how to install Java on Debian 11. For those of you who didn’t know, Java is one of the well-liked computer programming languages to develop PC or mobile apps and is available on various platforms. There are two different Java packages, Java Runtime Environment (JRE) and Java Development Kit (JDK). If you only want to run Java programs, then you need JRE, and if you are a Java developer, then you will need JDK, which includes JRE and development/debugging tools and libraries.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you through the step-by-step installation of Java on a Debian 11 (Bullseye).
Prerequisites
- A server running one of the following operating systems: Debian 11 (Bullseye).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Java on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt upgrade
Step 2. Installing Java on Debian 11.
- Install Java (OpenJDK 11) on Debian 11
To install the default JDK (Java Development Kit) on your system, run:
sudo apt install default-jre default-jdk
- Install Latest Java (OpenJDK 17) on Debian 11
To install the default JRE (Java Runtime Environment) on your system, run:
sudo apt install openjdk-17-jre openjdk-17-jdk
You can verify the installation of Java 11 by running the command below:
java -version
Step 3. Set Default Java Version.
You can have multiple versions of Java on your system, they can easily be managed by using the command:
sudo update-alternatives --config java
Output:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-17-openjdk-amd64/jre/bin/java 171 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Step 4. Configure Environment Variable.
To set the JAVA_HOME environment variable, you first need to find the default install location of JAVA. You can use the update-alternatives
command:
sudo update-alternatives --list java
Next, set the variable edit the /etc/environment
:
sudo nano /etc/environment
Add the following line, at the end of the file:
JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64/"
Save changes and close the file. Next, reload the file:
source /etc/environment
Verify the environment variable:
echo $JAVA_HOME
Output:
JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64/"
Congratulations! You have successfully installed Java. Thanks for using this tutorial for installing the latest version of Java on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Java website.