🚀 How to Install Java 21 Alongside Java 25 and Maven on Windows 10/11
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
Go to the official Oracle JDK download page: Oracle Java Downloads
Download Java SE Development Kit 21 for Windows x64 (
.exeinstaller).
🔹 Step 3: Install Java 21 Alongside Java 25
- Run the installer.
- Choose a separate installation path to avoid conflicts, e.g.:
C:\Program Files\Java\jdk-21
- Complete the installation.
✅ You now have Java 25 and Java 21 installed on your system.
🔹 Step 4: Configure JAVA_HOME for Java 21
- Press Win + S, search for Environment Variables, and open Edit the system environment variables → Environment Variables.
Under System variables, find
JAVA_HOME→ Edit:- Set the value to your Java 21 folder:
C:\Program Files\Java\jdk-21
- 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_HOMEand move%JAVA_HOME%\binto the top of Path to switch system-wide.
🔹 Step 7: Download and Install Apache Maven
- Go to Apache Maven Downloads and download the Binary zip archive of the latest version (e.g., 3.9.11).
- Extract it to a folder, e.g.:
C:\Maven\apache-maven-3.9.11
Set environment variables:
- M2_HOME →
C:\Maven\apache-maven-3.9.11 - Add
%M2_HOME%\binto Path.
- M2_HOME →
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
| Tool | Version |
| Java 21 | 21 LTS |
| Java 25 | 25 LTS (installed) |
| Maven | 3.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 terminalsetcommands to switch Java versions quickly for different projects.
