Multiple JDK Installation : Best Practise
Often as a developer one might have to install multiple versions of Java(JDK) and interchange between them depending on use case(Professional developement, trying latest JDK, experimenting with differnt vedors — oracle, Amazon Corretto, Red Hat).
You can install many java versions on a single system and depending on requirement you can select required version by simply changing Environment variables. In other words, env var is the controller
In this post, I intend to complile my understanding of several things one needs to keep in mind.
- Terminal
- Environment Variables - configuration & verification
- JDK installation
- IntelliJ idea
Terminal
The main commands for this context are
java --version: shows current java version recognized by system
—javac --version: shows current compiler recognized by systemwhere java: location of installation of current java
Environment Variable
- Windows reads Environment Variable Path list from Top to Bottom.
- Stop fast : as soon as it finds the first match it stops finding another path.
System32is almost always at the top of env variables meaning any installation in this path gets high priority.- After any fresh installation or adding new path variables, close System Properties tab to see effect of newly added paths.
- Althouth not tested but I would recommend in a similar way after deleting any env variable press ok and close this tab.
JDK Installation
- Prefer installing LTS versions (21, 25)
- Installation does three important things :
— creates files in :C:\Program Files\Java\jdk-XX(XX= version e.g 21, 25) (img 3)
— creates shortcuts of executables in :C:\Program Files\Common Files\Oracle\Java\javapath(img 4).
— also adds this path on top in Environment VariablesSystem Path(img 6).
Before Java 8 :
Oracle JDK installer would put a copy of java.exe into a high priority folder C:\Windows\System32 . This made it messay and hard to manage multiple versions.
After Java 8+ (SymLink Era) :
Oracle stopped putting in System32. Instead they created a hidden folder : C:\Program Files\Common Files\Oracle\Java\javapath
This folder contains “Symlink” (shortcut) pointing the latest JDK installation.
Note : Oracle installed forces this javapath folder to the very top of System Path
Note : the last JDK you installed (JDK 25) overwrites the symlinks in that folder and takes over your terminal, regardless of what JAVA_HOME you set.
Get kunalkrishna85’s stories in your inbox
Join Medium for free to get updates from this writer.
So whenever you install a new JDK you will loose acess to older JDK installations. How to use older versions?
> To access a specific JDK , create env_variable for that older java version which you want to use.
> Add this System Variable JAVA_HOME_21 inSystem Path : and place it below java 25 path.
To test java version close env variable setting winown and open a new terminal and type java -- version
You can have many more jdk installed and select to any . The only rule you need to remember is :
The java version which you want to use should be at higher level than other java version path in System Path .
Now let us see how to install 3rd java : openjdk-25.0.1
> Extract compressed file → this creates directory output openjdk-25.0.1_windows-x64_bin .
> Inside this lies jdk-25.0.1 . Copy this to your Java dir
> This directory contains the bin and therefore the path of this director needs to be added to system path inorder to make it usable.
Now apply the rule in sys path — move this new variable to top.
Test current version on, remember new, cmd : user java --versionor javac --version
Note : when the first value in Path starts with %(except %SystemRoot%) the window open differently (No move up, move down button). To fix this see this.
Fix : It is because it has % in it and it is not followed by SystemRoot. Windows recognizes variable Path having tompmost value starting with %AnyString as ordinary variable. Howerver, notable exception to this is $SystemRoot% which equals C:\WINDOWS . If you keep this on top, it still opens a detailed window. (This user reporeted from Win 11 experience)
IntelliJ Idea
InetelliJ allows to chose java version at project level. I will update more on this later.
Ctrl + Alt + Shit + S opens Project Structure settings.
Pressing green + button allows to add any installed java. These added SDKs are ready to be attached to any project. This makes any project modular. Any project can be coupled with any java enviornement.
Now to chose Java for a project. Open the project in InjelliJ IDE and see on top right. There chose Edit Config`
Now chose suitable Java version :






