For Ubuntu 22.04, you should be able to simply:
sudo apt install openjdk-21-jdk

It's in the Universe repository, so be sure you have that enabled.

It wasn't available yet when you asked the question, but it is now.

If you add a PPA or other non-Ubuntu version of OpenJDK, remember that it's likely to be incompatible with the (supported Ubuntu repository) Ubuntu package. So keep track of what you install; you might need to remove all of it.

Answer from user535733 on askubuntu.com
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_build_of_openjdk › 21 › html-single › installing_and_using_red_hat_build_of_openjdk_21_on_rhel › index
Installing and using Red Hat build of OpenJDK 21 on RHEL | Red Hat build of OpenJDK | 21 | Red Hat Documentation
Select the latest version of Red Hat build of OpenJDK 21 from the Version drop-down list, and then download the JRE archive for Linux to your local system. Extract the contents of the archive to a directory of your choice. ... When installed using this method, Java will only be available for ...
Discussions

How can i install Java 21 on Debian 12 without resorting to sid?
I recommend temurin jdk and they have their own packages. Zulu is also good. https://adoptium.net/installation/linux/ https://docs.azul.com/core/install/debian More on reddit.com
🌐 r/linux4noobs
26
25
July 15, 2024
Trying to install jdk 21. But it says already on the newest
It looks like you have both Java 21 and Java 17 installed. But the active version is Java 17. You can switch the active version with update-alternatives. You should check the doc of this command. But out of memory: sudo update-alternatives --config java This should open a dialog box that let you choose between the versions that are installed on your system. More on reddit.com
🌐 r/learnjava
11
6
November 4, 2024
How to install Java?
I think the first command will install the LTS version, which is currently 11. This has always been confusing on Debian distros. Are you just running java? Or are you looking to build new java code? Install the jdk if you want to build, not the jre. More on reddit.com
🌐 r/pop_os
4
5
February 25, 2020
Installing Java on Arch
https://wiki.archlinux.org/title/Java Should tell you basically anything you need. Also, you can use the community editions of intellij, I think they are available on the AUR. More on reddit.com
🌐 r/archlinux
8
4
July 31, 2021
🌐
RoseHosting
rosehosting.com › home › how to install java 21 on ubuntu 24.04
How to Install Java 21 on Ubuntu 24.04 | RoseHosting
May 8, 2024 - Once downloaded, you can install the package with the command below: ... root@host:~# java -version openjdk version "21.0.2" 2024-01-16 OpenJDK Runtime Environment (build 21.0.2+13-Ubuntu-2) OpenJDK 64-Bit Server VM (build 21.0.2+13-Ubuntu-2, ...
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › install › installation-jdk-linux-platforms.html
3 Installation of the JDK on Linux Platforms
July 15, 2025 - Anyone (not only root users) can install the archive file in any location having write access. ... The Java Development Kit files are installed into /usr/lib/jvm/jdk-<VERSION>-oracle-<ARCH> directory. For example, JDK 21 releases for x64 will be installed in /usr/lib/jvm/jdk-21-oracle-x64 directory.
🌐
LinuxVox
linuxvox.com › blog › install-java-21-linux
Installing Java 21 on Linux: A Comprehensive Guide — linuxvox.com
For example, if using Red Hat, you may need to subscribe to the appropriate channels. For CentOS, you can use the dnf package manager: ... Download the Java 21 JDK from the official Oracle or OpenJDK website.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-do-I-install-Java-on-Ubuntu
How to install Java 21 on Ubuntu
January 1, 2025 - Install the JDK with the following command: sudo apt install default-jre Setting up default-jdk-headless (2:1.21) ... Setting up openjdk-21-jdk:amd64 (21.0.5+11-1ubuntu~24.04.1) ...
🌐
Reddit
reddit.com › r/linux4noobs › how can i install java 21 on debian 12 without resorting to sid?
r/linux4noobs on Reddit: How can i install Java 21 on Debian 12 without resorting to sid?
July 15, 2024 -

EDIT: I've ended up installing Microsoft's OpenJDK 21. Had a nice instructions to setup and i didnt need to mess up my debian repositories to get the thing (only add MS one). Sorry die-hard Linux fans

I'm trying to install the JRE of Java 21 in my Debian 12 headless machine, for Minecraft server purposes.

Unfortunately i saw that the packages of 21 aren't available in stable repositories, only on sid (unstable). I don't want to add the whole sid repository to avoid instability and since the only package i want is this one.

So, is there any way to install Java 21 using either apt or a .deb file - without resorting to unpack a .tar.gz? Should i download the .deb on the website and try to install it via gdebi-core? I read that this isn't an advised thing to do due to dependencies and such...

Find elsewhere
🌐
Oracle
oracle.com › java › technologies › downloads
Download the Latest Java LTS Free
Linux · macOS · Windows · Documentation Download · Online Documentation · Installation Instructions · Release Notes · Documentation License · JDK 25 Licensing Information User Manual (includes third-party licenses) Certified System Configurations · Readme · Java Value Engineering · JDK 21 binaries are free to use in production and free to redistribute, at no cost, under the Oracle No-Fee Terms and Conditions (NFTC).
🌐
javathinking
javathinking.com › blog › jdk-21-install-linux
Installing JDK 21 on Linux: A Comprehensive Guide — javathinking.com
sudo update-alternatives --config java # Select the JDK 21 path from the list sudo update-alternatives --config javac # Repeat for javac · Cause: Incorrect file permissions on the JDK directory. Fix: Set ownership to root (system-wide) or your user (user-specific): sudo chown -R root:root /usr/lib/jvm/jdk-21.0.1+12 # System-wide # OR chown -R $USER:$USER ~/jdk21 # User-specific · Cause: SDKMAN! initialization not loaded in the shell. ... By following this guide, you’ll have JDK 21 installed and configured on your Linux system, ready for development or production use.
🌐
ComputingForGeeks
computingforgeeks.com › home › install java 21 (openjdk 21) on ubuntu 24.04|22.04|20.04
Install Java 21 (OpenJDK 21) on Ubuntu [Guide]
March 21, 2026 - Step-by-step guide to java 21 (OpenJDK 21) on Ubuntu 24.04|22.04|20.04. Includes commands, verification, and troubleshooting.
🌐
TecMint
tecmint.com › home › debian › how to install java jdk 21 on debian 12
How to Install Java 21 (JDK) on Debian 12
June 27, 2024 - The easiest way to install Java 21 on Debian 12 is by using the apt package manager as a regular user with sudo privileges and updating the system packages as shown. ... If you want to check if Java is installed, run the command.
🌐
UbuntuHandbook
ubuntuhandbook.org › home › howtos › install oracle java jdk 21, 25, or 26 in ubuntu 24.04 | 22.04 | 20.04
Install Oracle Java JDK 21, 25, or 26 in Ubuntu 24.04 | 22.04 | 20.04 | UbuntuHandbook
sudo apt install ~/Downloads/jdk-21_linux-x64_bin.deb · Here replace 21 in command if you downloaded JDK 25 or 26. Or, just drag and drop the .deb package from your downloads folder into terminal to auto-insert path to that file. The .deb package include a post-install script that automatically ...
🌐
Java With Us
javawithus.com › home › faq › how to install java on linux (all distros)
How to Install Java on Linux (All Distros) | Java With Us
April 21, 2026 - Linux has the easiest Java install path of any OS — every major distribution ships OpenJDK in its standard package manager. One command gets you a working JDK. sudo apt update sudo apt install openjdk-21-jdk java -version
🌐
Javadownload
javadownload.org › blog › java-21-install
How to Install Java 21 (LTS): A Complete Guide for Windows, macOS, and Linux — javadownload.org
May 11, 2026 - The easiest way to install Java 21 on Ubuntu or Debian is through the official repositories: ... Download the Linux .tar.gz from a provider like Oracle or Adoptium.
🌐
AWS
docs.aws.amazon.com › corretto › corretto 21 user guide › amazon corretto 21 guide for linux › amazon corretto 21 installation instructions for debian-based, rpm-based and alpine linux distributions
Amazon Corretto 21 Installation Instructions for Debian-Based, RPM-Based and Alpine Linux Distributions - Amazon Corretto 21
After the repository is added, you can install Corretto 21 by running this command: ... Download the Linux .rpm file from the Downloads page. Install the downloaded .rpm file using yum localinstall. For example install x86_64 rpm using the following command: sudo yum localinstall java-21-ama...
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_build_of_openjdk › 21 › html › installing_and_using_red_hat_build_of_openjdk_21_on_rhel › installing-openjdk-on-rhel_openjdk
Chapter 2. Installing Red Hat build of OpenJDK 21 on Red Hat Enterprise Linux | Installing and using Red Hat build of OpenJDK 21 on RHEL | Red Hat build of OpenJDK | 21 | Red Hat Documentation
Select the latest version of Red Hat build of OpenJDK 21 from the Version drop-down list, and then download the JRE archive for Linux to your local system. Extract the contents of the archive to a directory of your choice. ... When installed using this method, Java will only be available for ...
🌐
Linuxize
linuxize.com › home › java › how to install java on ubuntu 24.04
How to Install Java on Ubuntu 24.04 | Linuxize
May 3, 2026 - Install Java 25, Java 21, and Oracle JDK on Ubuntu 24.04. This guide covers OpenJDK packages, default Java selection, and JAVA_HOME setup.
🌐
LinuxVox
linuxvox.com › blog › install-java-21-ubuntu
Installing Java 21 on Ubuntu: A Comprehensive Guide — linuxvox.com
# Add the Adoptium GPG key wget ... apt install temurin - 21 - jdk · Download Java 21 Visit the Adoptium website and download the appropriate Java 21 JDK binary for Linux (usually in .tar.gz format)....
🌐
Linux Today
linuxtoday.com › home › blog
How to Install Java 21 on Debian 13 | Linux Today
June 26, 2025 - 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++.