Skip to main content

Command Palette

Search for a command to run...

🚀 How to Install Java 21 Alongside Java 25 and Maven on Windows 10/11

Updated
3 min read

Sometimes developers need to work with multiple Java versions for different projects. In this tutorial, I’ll show you how to install Java 21 alongside Java 25, configure environment variables, and set up Apache Maven on Windows.


🔹 Step 1: Check Existing Java Installation

Open Command Prompt and run:

java -version
javac -version

Example output if Java 25 is installed:

java version "25" 2025-09-16 LTS
javac 25

⚠️ If you see mismatched versions or want to add Java 21, follow the next steps.


🔹 Step 2: Download Java 21 JDK

  1. Go to the official Oracle JDK download page: Oracle Java Downloads

  2. Download Java SE Development Kit 21 for Windows x64 (.exe installer).


🔹 Step 3: Install Java 21 Alongside Java 25

  1. Run the installer.
  2. Choose a separate installation path to avoid conflicts, e.g.:
C:\Program Files\Java\jdk-21
  1. Complete the installation.

✅ You now have Java 25 and Java 21 installed on your system.


🔹 Step 4: Configure JAVA_HOME for Java 21

  1. Press Win + S, search for Environment Variables, and open Edit the system environment variablesEnvironment Variables.
  2. Under System variables, find JAVA_HOMEEdit:

    • Set the value to your Java 21 folder:
C:\Program Files\Java\jdk-21
  1. Ensure your Path includes:
%JAVA_HOME%\bin
  • Move it to the top of the PATH list to prioritize Java 21 over Java 25.

  • Click OK to save.


🔹 Step 5: Verify Java 21 Installation

Open a new Command Prompt and run:

java -version
javac -version

Expected output:

java version "21.0.x" 2025-07-15 LTS
javac 21

🎉 Your system now uses Java 21, while Java 25 remains installed for other projects.


🔹 Step 6: Optional – Switching Between Java Versions

If you want to switch between Java 21 and Java 25:

Temporary Switch in a Terminal

set JAVA_HOME=C:\Program Files\Java\jdk-25
set PATH=%JAVA_HOME%\bin;%PATH%
java -version
javac -version

This affects only the current terminal session.

Permanent Switch

  • Change JAVA_HOME and move %JAVA_HOME%\bin to the top of Path to switch system-wide.

🔹 Step 7: Download and Install Apache Maven

  1. Go to Apache Maven Downloads and download the Binary zip archive of the latest version (e.g., 3.9.11).
  2. Extract it to a folder, e.g.:
C:\Maven\apache-maven-3.9.11
  1. Set environment variables:

    • M2_HOMEC:\Maven\apache-maven-3.9.11
    • Add %M2_HOME%\bin to Path.
  2. Open a new Command Prompt and check:

mvn -version

Expected output:

Apache Maven 3.9.11
Java version: 21, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk-21

🔹 Step 8: Optional – Test a Maven Project

Create a sample Maven project:

mvn archetype:generate -DgroupId=com.example -DartifactId=MyApp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd MyApp
mvn compile
mvn exec:java -Dexec.mainClass="com.example.App"

This ensures your Maven and Java setup works end-to-end.


🔹 Summary Table

ToolVersion
Java 2121 LTS
Java 2525 LTS (installed)
Maven3.9.11

✅ Conclusion

You now have Java 21 installed alongside Java 25 and a working Maven environment on Windows.

This setup lets you switch between Java versions for different projects while keeping your system organized and conflict-free.

💡 Pro Tip: Use JAVA_HOME + PATH order or terminal set commands to switch Java versions quickly for different projects.


More from this blog

Vinay206

10 posts