Install OpenJDK 21 LTS on Ubuntu 24.04|22.04|20.04|18.04
JDK 21 is a long-term support (LTS) release from most vendors.
OpenJDK (Open Java Development Kit) is an open-source implementation of the Java Platform, Standard Edition (Java SE) licensed under the GNU General Public License, which provides a complete runtime environment for executing Java applications and a development environment for building Java applications. OpenJDK is governed by the OpenJDK Community, and its development is led by Oracle, with contributions from various companies and individuals.
OpenJDK 21, released in September 2023, is a production-ready open-source builds of the Java Development Kit, version 21, an implementation of the Java SE 21 Platform. It introduces several new features and improvements to the Java platform. Key enhancements in OpenJDK 21 include updates to the language, the JDK internals, performance optimizations, and the introduction of new features such as pattern matching for switch statements and virtual threads, which improve both the usability and performance of Java applications, especially in the context of modern multicore processors.
To install OpenJDK 21, visit OpenJDK GA Release Page and get the latest version of OpenJDK 21 for your CPU architecture. The latest available version of OpenJDK 21 is 21.0.2.
1 | wget https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2_linux-x64_bin.tar.gz |
Extract downloaded archive.
1 | tar xvf openjdk-21.0.2_linux-x64_bin.tar.gz |
Set environment variables inside /etc/profile.d/ directory. For example:
1 | vim /etc/profile.d/dev-conf.sh |
Source the files to make variables available in your current shell session.
1 | source /etc/profile.d/dev-conf.sh |
Confirm Java version using the java -version
command.
1 | $ java -version |