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
🌐
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 - Download the key file from https://yum.oracle.com/RPM-GPG-KEY-oracle-ol9 using the following command: wget https://yum.oracle.com/RPM-GPG-KEY-oracle-ol9 ... Note:Public key installation needs to be done only once. The key installation is persistent across reboots.
🌐
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) ...
🌐
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, ...
🌐
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
Create a directory to where you want to download the archive file, and then navigate to that directory on your command-line interface (CLI). For example: ... Navigate to the Software Downloads page on the Red Hat Customer Portal. Select the latest version of Red Hat build of OpenJDK 21 from ...
🌐
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 - The easiest and quickest way is installation OpenJDK 21 on Ubuntu 24.04|22.04|20.04 from OS upstream repositories. sudo apt update -y sudo apt install -y openjdk-21-jdk · For JRE run the following commands to install.
Find elsewhere
🌐
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 ...
🌐
Develop n Solve
developnsolve.com › linux › how-to-install-java-21-linux
How to Install Java 21 on Linux
Supported Linux distribution: Ensure ... with Java 21 packages. Root or sudo access: Administrative privileges are required to install software and configure environment variables on your system. Basic terminal knowledge: Familiarity with Linux command line helps in downloading, ...
🌐
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 - Please try again. 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...
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to install java on ubuntu
How to Install Java on Ubuntu
February 20, 2025 - This step-by-step guide will show you how to install Java on Ubuntu. ... A user account with sudo or root privileges. Access to the terminal. An Ubuntu Linux system.
🌐
Javadownload
javadownload.org › blog › java-21-install-linux
How to Install Java 21 LTS on Linux: A Complete Step-by-Step Guide — javadownload.org
May 11, 2026 - sudo mkdir -p /usr/lib/jvm sudo tar -xzf jdk-21_linux-x64_bin.tar.gz -C /usr/lib/jvm # Note: Adjust filename based on download · Set global environment variables to add Java to your PATH: # Add to ~/.bashrc or /etc/profile export ...
🌐
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
🌐
XDA Developers
xda-developers.com › home › java › how to install java on ubuntu
How to install Java on Ubuntu
March 1, 2024 - You can choose Java 17 or Java 21. When the download is complete, double-click to launch it. Click the green Install button. Enter your password. Once the installation is complete, you'll be able to see Oracle Java in your list of applications. If you want, you can also install it manually without going through the web browser by typing out the following commands, pressing Enter in between each line...
🌐
javaspring
javaspring.net › blog › how-to-install-java-21
Installing Java 21: A Comprehensive Guide — javaspring.net
Extract the archive: If you downloaded a compressed archive (.tar.gz), extract it to a desired location. For example, if you downloaded the file to your home directory, you can use the following command in the terminal: tar -xvf jdk-21_linux-x64_bin...
🌐
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.
🌐
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
Create a directory to where you want to download the archive file, and then navigate to that directory on your command-line interface (CLI). For example: ... Navigate to the Software Downloads page on the Red Hat Customer Portal. Select the latest version of Red Hat build of OpenJDK 21 from ...
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › How-to-install-Java-21
How to download and install Java 21 on Windows
Extract the Java 21 zip file to a sensible location on your filesystem. Configure the JAVA_HOME environment variable. Add the JDK’s \bin directory to the PATH of your OS. Issue a java -version command to ensure the Java 21 install succeeded.
🌐
Oracle
java.com › en › download › help › linux_install.html
How do I download and install 32-bit Java for Linux?
Instructions to download and install the Java Runtime Environment (JRE) for 32-bit Linux
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-install-java-with-apt-on-ubuntu-22-04
How to Install Java with Apt on Ubuntu (JRE & JDK) | DigitalOcean
February 2, 2026 - 11.0.13_linux-x64_bin.tar.gz /var/cache/oracle-jdk11-installer-local/ ... The installer will first ask you to accept the Oracle license agreement. Accept the agreement, then the installer will extract the Java package and install it. Now you’ll look at how to select the version of Java you want to use. You can have multiple Java installations on one server. You can configure which version is used by default on the command line by using the update-alternatives command.