How to download and install Java 21

The latest long-term support (LTS) release of the JDK is Java 21, which was released in September of 2023.

How install Java 21 on Windows

If you’re interested in getting up to speed with the latest Java release and testing out many of the new preview features, follow these steps to quickly install Java 21 on your Windows or Linux desktop:

  1. Navigate to jdk.java.net/21/ and download your platform’s zip file.
  2. Extract the Java 21 zip file to a sensible location on your filesystem.
  3. Configure the JAVA_HOME environment variable.
  4. Add the JDK’s \bin directory to the PATH of the OS.
  5. Issue a java -version command to ensure the Java 21 install succeeded.

Where do I download the Java 21 JDK?

There are many distributions of Java that are built from the same, open-source JDK. The Azul and Red Hat distributions are two of my favorites, and I love the open source Adoptium Temurin edition from Eclipse, but Oracle is the steward of the platform, so downloading and installing the OpenJDK from them at jdk.java.net/21 is always a safe bet.

install Java 21 JDK

To install Java 21, first download the early access JDK release.

Extract the contents of the Java 21 JDK zip file

The download is just a zip file, so you can extract the contents anywhere onto your local file system.

The extraction contains a folder named java-21. Copy this folder to where you want the Java 21 JDK to permanently reside.

In this example, I’ve copied the Java 21 JDK to a folder named C:\_tools.

Configure JAVA_HOME for the JDK

It’s customary to add an environment or system variable named JAVA_HOME that points to the location of the JDK install.

Set JAVA_HOME for Java 21

It is customary to add a JAVA_HOME environment variable when you install the Java 21 JDK.

Why set JAVA_HOME?

Your Java installation will still run if you don’t set JAVA_HOME, but this system variable accomplishes two important purposes:

  • It tells programs that have a Java dependency on where the JDK is installed.
  • If multiple JDKs are installed, JAVA_HOME points to the preferred Java instance to use.

Add the Java 21 \bin directory to the PATH

To make the Java runtime, along with various other important utilities, available through the command line you must add the location of the Java 21 \bin directory to the operating system’s PATH variable.

Java PATH installation

Always add the Java 21 JDK’s \bin directory to the PATH.

Along with the Java compiler and the Java runtime executable, adding the Java 21 \bin directory to the path provides command-line access to:

The PATH must point to the JDK’s \bin directory, not the root of the installation folder as with JAVA_HOME.

Verify the Java 21 install

Once you’ve installed the JDK, set JAVA_HOME and updated the PATH, open up a terminal window and type the following:

java -version

The result of this operation should confirm a successful Java 21 early edition installation.

successful JDK 21 install

The java -version command validates the installation of the JDK.

Java 21 functionality and preview features

With the Java 21 install complete, go ahead and compile some code and test out some of the exciting Java 21 preview features and core functionality including the following:

  • Unnamed classes.
  • Instance main methods.
  • Unnamed patterns.
  • Generational ZGC.
  • Record patterns.
  • Switch pattern matching.
  • Sequenced collections.
  • Virtual threads.
  • The Vector API
  • Apache Maven build features

Java 21 will have a huge impact on the way programmers approach DevOps and  modern software development.

App Architecture
Software Quality
Cloud Computing
Security
SearchAWS
Close