In this blog post, we will explain how to install Java 21 on Debian 13 OS in detail. Java is a high-level, object-oriented programming language with a syntax similar to C and C++. It was developed to let programmers write code in Java once and compile it everywhere, making it compatible with multiple platforms without recompiling. Java comes in three different editions: JRE, JDK, and OpenJDK.
JRE stands for Java Runtime Environment. It is a software layer that runs on top of a server operating system and provides class libraries and other resources.
JDK stands for Java Development Kit, a distribution of Java technology by Oracle Corporation. It implements the Java Language Specification and Java Virtual Machine and provides a standard Java Application Programming Interface edition.
OpenJDK or Open Java Development Kit is a free and open-source implementation of the Java Platform, Standard Edition (Java SE).
Installing Java 21 on Debian 13 is straightforward and may take up to 15 minutes. Let’s get started!
Table of Contents
Prerequisites
- A server running Debian 13 OS
- User privileges: root or non-root user with sudo privileges
Update the System
Before we start installing Java, we assume you have a freshly installed OS so that we can update the system packages to their latest versions. To do that, execute the following command:
sudo apt update -y && sudo apt upgrade -y
How do you install Java 21 from a repository?
Java 21 is already included in the default repo of the latest Debian 13 OS. To facilitate the installation of Java 21, we need to execute the following command:
sudo apt install openjdk-21-jdk -y
After successful installation, to check the installed Java version, you can execute the command below:
java -version
If everything is OK, you should get output similar to this:
root@host:~# java -version openjdk version "21.0.7-ea" 2025-04-15 OpenJDK Runtime Environment (build 21.0.7-ea+8-Debian-1) OpenJDK 64-Bit Server VM (build 21.0.7-ea+8-Debian-1, mixed mode, sharing)
How to Install Oracle Java 21?
The Oracle Java 21 is not included by default in the Debian 13 repo, and that is why we need to download it from the official Java Oracle website:
cd /opt wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb
Once downloaded, we can install Oracle Java 21 with the following command:
sudo apt install ./jdk-21_linux-x64_bin.deb
Once installed, to check the Java version, you can use the same command:
java -version
If everything is OK, you should get the following output:
root@host:/opt# java -version java version "21.0.7" 2025-04-15 LTS Java(TM) SE Runtime Environment (build 21.0.7+8-LTS-245) Java HotSpot(TM) 64-Bit Server VM (build 21.0.7+8-LTS-245, mixed mode, sharing)
The main difference between the two outputs of the versions is highlighted to notice the differences between the OpenJDK and Oracle Java.
How to Manage Multiple Java versions?
We have installed OpenJDK and Oracle Java 21 versions. They are installed and available on the server. If you execute the command java -version, you will get the output about one of the installed editions. That is because only one Java edition can be active. To list the available Java editions and set some Java to be active first, you need to execute the following command:
sudo update-alternatives --config java
Then you will get output similar to this:
root@host:~# sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/java 352378880 auto mode 1 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 2111 manual mode 2 /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/java 352378880 manual mode Press to keep the current choice[*], or type selection number:
The active Java is Oracle Java 21, which is checked with *. To change the Java edition, in this case, you need to type number 1 and hit Enter.
After this, the active Java will be the OpenJDK.
Press to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/lib/jvm/java-21-openjdk-amd64/bin/java to provide /usr/bin/java (java) in manual mode root@host:~# sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/java 352378880 auto mode * 1 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 2111 manual mode 2 /usr/lib/jvm/jdk-21.0.7-oracle-x64/bin/java 352378880 manual mode
That’s it. You successfully installed Java 21 on Debian 13 and learned to switch between the different editions with a straightforward command.
Of course, if you have difficulties and are unfamiliar with Linux, you don’t have to install Java 21 on Debian 13. You can always contact our technical support. You only need to sign up for one of our Linux VPS plans and submit a support ticket. We are available 24/7 and will take care of your request immediately.
If you liked this post about how to install Java 21 on Debian 13, please share it with your friends or leave a comment below.