Step 1 — Go to the official Oracle download page
Visit [Link] and scroll down to the Java 21
section. You can download a zip archive, EXE installer, or MSI installer. The EXE installer is
recommended because it updates the environment variable PATH automatically, making
installation simple and easy.
Step 2 — Run the installer
Start the JDK 21 installer by double-clicking the installer's icon or file name in the download
location. You must have administrator privileges to install the JDK on Microsoft Windows.
The setup wizard will open — click Next twice to proceed with the default installation directory.
The default installation directory is C:\Program Files\Java\jdk-21. The installer will update the
system environment variable PATH automatically, putting C:\Program Files\Common
Files\Oracle\Java\javapath as the first entry.
Step 3 — Set JAVA_HOME environment variable
It is customary to add a JAVA_HOME environment variable when you install the Java 21 JDK.
This accomplishes two important purposes: it tells programs with a Java dependency where the
JDK is installed, and if multiple JDKs are installed, JAVA_HOME points to the preferred Java
instance to use.
To set it manually:
1. Right-click This PC → Properties → Advanced System Settings
2. Click Environment Variables
3. Under System Variables, click New
4. Variable name: JAVA_HOME
5. Variable value: C:\Program Files\Java\jdk-21
Step 4 — Add JDK bin to PATH
Always add the Java 21 JDK's \bin directory to the PATH. Along with the Java compiler and
runtime executable, this provides command-line access to JShell, the JavaP decompiler, JDeps,
JavaDoc, and the JAR signer utility. The PATH must point to the JDK's \bin directory, not the
root of the installation folder.
In Environment Variables → System Variables → find Path → click Edit → New → add:
“ %JAVA_HOME%\bin “
Move this entry to the top of the list to prioritize JDK 21 over older versions. Click OK to save
all changes. Close and reopen any open terminals for changes to take effect.
Step 5 — Verify the installation
Open a new Command Prompt and type:
java -version
javac -version
It will print the version of the Java Virtual Machine ([Link]) and Java compiler ([Link]).
This means Oracle JDK 21 has been installed successfully on the Windows operating system,
and you will be able to create, develop, build, and execute applications running on the Java
Virtual Machine. CodeJava
You should see output like:
java version "21.0.x" 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21.0.x+...)
Java HotSpot(TM) 64-Bit Server VM