How To Change Java Version In Windows
In this article, I will show you how to install multiple Java versions on Windows and how to change the Java version on the control line:

To enable these Java version modify commands on your system as well, follow this step-by-step guide.
Permit's become…
Pace 1: Installing Multiple Coffee Versions
Installing multiple Coffee versions in parallel is incredibly easy in Windows. You can download and run the installer for each version, which automatically installs the versions in separate directories.
Download Sources
- Java SE 1.one – Y'all can no longer install this version on 64-scrap Windows.
- Java SE 1.two – Installed to
C:\jdk1.2.2\
andC:\Program Files (x86)\JavaSoft\JRE\1.two\
by default – I recommend changing this toC:\Plan Files (x86)\Java\jdk1.2.2\
andC:\Program Files (x86)\Java\jre1.two.two\
for the sake of clarity. - Java SE 1.iii – Installed to
C:\jdk1.3.1_28\
by default – I recommend changing this toC:\Program Files (x86)\Java\jdk1.iii.1_28\
. - Coffee SE one.4 – Installed to
C:\j2sdk1.4.2_19\
by default – I recommend irresolute this toC:\Program Files (x86)\Coffee\jdk1.4.2_19\
.
Starting with the following versions, you lot don't need to change the default installation directories:
- Coffee SE v
- Java SE half-dozen
- Java SE seven
- Java SE 8
- Coffee SE nine / OpenJDK 9
- Java SE 10 / OpenJDK 10 (→ The near important new features in Java x)
Attending – y'all may use the following Oracle distributions only for private purposes and development:
- Coffee SE 11 / OpenJDK xi (→ The most important new features in Java eleven)
- Coffee SE 12 / OpenJDK 12 (→ The most important new features in Java 12)
- Coffee SE xiii / OpenJDK 13 (→ The about important new features in Java 13)
- Coffee SE 14 / OpenJDK 14 (→ The most important new features in Java 14)
- Java SE xv / OpenJDK xv (→ The nearly of import new features in Coffee 15)
- Coffee SE 16 / OpenJDK xvi (→ The most of import new features in Coffee 16)
- Java SE 17 / OpenJDK 17 (→ The most important new features in Java 17)
- Coffee SE eighteen / OpenJDK eighteen (→ The well-nigh important new features in Coffee 18)
The post-obit version is currently an early access build. You should use information technology only for testing purposes:
- JDK 19 Early on-Access Build
Footstep two: Define Java Environment Variables
The following two environment variables make up one's mind which Java version an application uses:
-
JAVA_HOME
– many outset scripts use this variable. -
Path
– is used when running a Coffee binary (such asjava
andjavac
) from the console.
These variables should always betoken to the same Java installation to avoid inconsistencies. Some programs, such equally Eclipse, ascertain the Coffee version in a separate configuration file (for Eclipse, for example, this is the entry "-vm" in the eclipse.ini
file).
Manually Setting the Coffee Environs Variables
The Java installers create various environment variables, which you lot demand to clean upwards first (run across below). The fastest fashion to change the surround variables is to press the Windows key and type "env" – Windows then offers "Edit the organization environment variables" as a search result:

At this signal, y'all can press "Enter" to open the system properties:

Click on "Environment Variables…" and the following window opens:

As the default version, I recommend the current release version, Java 18. Accordingly, you should brand the post-obit settings:
- The top list ("User variables") should not comprise any Java-related entries.
- The lower list ("System variables") should incorporate an entry "JAVA_HOME = C:\Plan Files\Java\jdk-18". If this entry does not exist, you can add it with "New…". If information technology exists but points to another directory, you can change it with "Edit…".
- Delete the following entries nether "Path":
-
C:\ProgramData\Oracle\Java\javapath
-
C:\Programme Files (x86)\Common Files\Oracle\Coffee\javapath
-
- Insert the following entry instead:
-
%JAVA_HOME%\bin
-
The entry should then look like the following (the other entries in the list will probably look different for you since you have other applications installed than I do):

The final entry ensures that Path
and JAVA_HOME
are automatically consistent.
Attending: this only works for the default setting configured here. If you alter JAVA_HOME
via the command line, you have to adjust Path
accordingly. Merely don't worry – the scripts you can download in the next step will practise that automatically.
How to Bank check Your Java Version on Windows
Now open a control line to check the settings with the following commands:
Code language: plaintext ( plaintext )
echo %JAVA_HOME% coffee -version
Here's what you should encounter:

Step iii: Install the Scripts to Modify the Java Version
To change the Java version on the command line, I have prepared some batch files that you can copy to your organization. Here is the link: scripts-up-to-java19.zip
The Zippo file contains scripts named java19.bat
, java18.bat
, java17.bat
, etc., for all Java versions. I suggest you lot unpack the scripts to C:\Program Files\Java\scripts
.
The scripts look similar this (java18.bat
):
@repeat off set up JAVA_HOME=C:\Plan Files\Coffee\jdk-18 set Path=%JAVA_HOME%\bin;%Path% echo Java 18 activated.
Lawmaking linguistic communication: DOS .bat ( dos )
The script updates the JAVA_HOME
environs variable and inserts the bin
directory at the beginning of the Path
variable. That makes it the first directory to be searched for the corresponding executable when you lot run Java commands such every bit java
or javac
.
(The Path
variable gets longer with each change. Do not worry nearly it. This only affects the currently opened control line.)
Step 4: Add the Script Directory to the Path
To be able to call the scripts from anywhere, yous take to add the directory to the "Path" surround variable (just similar yous did with "%JAVA_HOME%\bin" in the 2d footstep):

If you lot have installed the latest releases of all Coffee versions, you can use the scripts without any further adjustments. Open a new command line and enter, e.g., the following commands:

If one of the commands does non activate the expected Coffee version, please check if the path in the batch file corresponds to the installation path of the Java version you want to activate.
Temporary, Permanent, and System-Broad Java Version Changes
The commands presented upwards to this point only affect the currently opened command line. Every bit soon every bit you open up some other command line, the default version defined in step 2 is agile again (Coffee 18, if y'all have not changed anything).
That is why there are not 1 but three scripts for each Java version:
-
java<version>
: Activates the Java version in the current control line. -
java<version>-user
: Sets the Java version as the default version for your user account. -
java<version>-organisation
: Sets the Coffee version as the default version for the entire system-
The -user
variants of the scripts additionally set the JAVA_HOME
environs variable with the setx
command, permanently writing the change to the registry:
@echo off prepare JAVA_HOME=C:\Program Files\Coffee\jdk-18 setx JAVA_HOME "%JAVA_HOME%" fix Path=%JAVA_HOME%\bin;%Path% echo Java eighteen activated equally user default.
Lawmaking language: DOS .bat ( dos )
The -organisation
variants likewise specify the /Thou
parameter in the setx
command. This sets the organization-wide environs variable instead of the user-specific ane:
@echo off set JAVA_HOME=C:\Plan Files\Java\jdk-18 setx JAVA_HOME "%JAVA_HOME%" /One thousand set Path=%JAVA_HOME%\bin;%Path% echo Coffee 18 activated as system-wide default.
Code language: DOS .bat ( dos )
Attention: To set the system-wide Java version, you must open the command line as an administrator. Otherwise, yous volition become the error message "ERROR: Access to the registry path is denied.
What You Should Do Next…
I hope you were able to follow the instructions well and that the commands work for you.
Now I would like to hear from you lot:
Were you lot able to follow the steps well – or do you take unanswered questions?
Either mode, permit me know by leaving a comment below.
Source: https://www.happycoders.eu/java/how-to-switch-multiple-java-versions-windows/
Posted by: tranwhempos60.blogspot.com
0 Response to "How To Change Java Version In Windows"
Post a Comment