How to install Java 21

How to download and install Java 21

The next long-term support (LTS) release of the JDK will be officially released in September of this year. If you’re interested in testing out any of the new preview features, here’s how to quickly install Java 21 on your Windows or Linux desktop:

  1. Navigate to 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?

Once Java 21 goes GA, I recommend to download a distribution from Adoptium or Azul, or even Microsoft. For early access you must go to and download the latest build of the OpenJDK.

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.

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

App Architecture
Software Quality
Cloud Computing