How to change java version on 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 command line and in PowerShell:

Multiple Java versions on Windows

To enable these Java version change commands on your system as well, follow this step-by-step guide.

Let’s go…

Step 1: Installing Multiple Java Versions

Installing multiple Java 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.1 – You can no longer install this version on 64-bit Windows.
  • Java SE 1.2 – Installed to C:\jdk1.2.2\ and C:\Program Files (x86)\JavaSoft\JRE\1.2\ by default – I recommend changing this to C:\Program Files (x86)\Java\jdk1.2.2\ and C:\Program Files (x86)\Java\jre1.2.2\ for the sake of clarity.
  • Java SE 1.3 – Installed to C:\jdk1.3.1_28\ by default – I recommend changing this to C:\Program Files (x86)\Java\jdk1.3.1_28\.
  • Java SE 1.4 – Installed to C:\j2sdk1.4.2_19\ by default – I recommend changing this to C:\Program Files (x86)\Java\jdk1.4.2_19\.

Starting with the following versions, you don’t need to change the default installation directories:

  • Java SE 5
  • Java SE 6
  • Java SE 7
  • Java SE 8
  • Java SE 9 / OpenJDK 9
  • Java SE 10 / OpenJDK 10 (→ The most important new features in Java 10)

Attention – you may use the following Oracle distributions only for private purposes and development:

  • Java SE 11 / OpenJDK 11 (→ The most important new features in Java 11)
  • Java SE 12 / OpenJDK 12 (→ The most important new features in Java 12)
  • Java SE 13 / OpenJDK 13 (→ The most important new features in Java 13)
  • Java SE 14 / OpenJDK 14 (→ The most important new features in Java 14)
  • Java SE 15 / OpenJDK 15 (→ The most important new features in Java 15)
  • Java SE 16 / OpenJDK 16 (→ The most important new features in Java 16)
  • Java SE 17 / OpenJDK 17 (→ The most important new features in Java 17)
  • Java SE 18 / OpenJDK 18 (→ The most important new features in Java 18)
  • Java SE 19 / OpenJDK 19 (→ The most important new features in Java 19)
  • Java SE 20 / OpenJDK 20 (→ The most important new features in Java 20)
  • Java SE 21 / OpenJDK 21 (→ The most important new features in Java 21)

The following version is currently an early access build. You should use it only for testing purposes:

  • JDK 22 Early-Access Build

Step 2: Define Java Environment Variables

The following two environment variables decide which Java version an application uses:

  • JAVA_HOME – many start scripts use this variable.
  • Path – is used when running a Java binary (such as java and javac) from the console.

These variables should always point to the same Java installation to avoid inconsistencies. Some programs, such as Eclipse, define the Java version in a separate configuration file (for Eclipse, for example, this is the entry «-vm» in the eclipse.ini file).

Manually Setting the Java Environment Variables

The Java installers create various environment variables, which you need to clean up first (see below). The fastest way to change the environment variables is to press the Windows key and type «env» – Windows then offers «Edit the system environment variables» as a search result:

Opening Windows environment variables
Opening Windows environment variables

At this point, you can press «Enter» to open the system properties:

Windows System Properties
Windows System Properties

Click on «Environment Variables…» and the following window opens:

Windows environment variables Java 20
Windows environment variables Java 20

As the default version, I recommend the current release version, Java 20. Accordingly, you should make the following settings:

  • The top list («User variables») should not contain any Java-related entries.
  • The lower list («System variables») should contain an entry «JAVA_HOME = C:\Program Files\Java\jdk-20». If this entry does not exist, you can add it with «New…». If it exists but points to another directory, you can change it with «Edit…».
  • Delete the following entries under «Path» (if they exist):
    • C:\ProgramData\Oracle\Java\javapath
    • C:\Program Files (x86)\Common Files\Oracle\Java\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):

Adding "%JAVA_HOME%\bin" to the "Path" system variable
Adding «%JAVA_HOME%\bin» to the «Path» system variable

The last entry ensures that Path and JAVA_HOME are automatically consistent.

Attention: this only works for the default setting configured here. If you change JAVA_HOME via the command line, you have to adjust Path accordingly. But don’t worry – the scripts you can download in the next step will do that automatically.

How to Check Your Java Version on Windows

Now open a command line to check the settings with the following commands:

echo %JAVA_HOME%
java -versionCode language: plaintext (plaintext)

Here’s what you should see:

Check your Java version with "cmd"
Check your Java version with «cmd»

Step 3: Install the Scripts to Change the Java Version

To change the Java version on the command line, I have prepared some batch files that you can copy to your system. Here is the link: scripts-up-to-java21.zip

The ZIP file contains scripts named

  • java21.bat, java20.bat, java19.bat, etc., for all Java versions,
  • the corresponding files java21.ps1, java20.ps1, etc. for PowerShell,
  • plus two common scripts javaX.bat and javaX.ps1.

I suggest you unpack the scripts to C:\Program Files\Java\scripts.

The scripts look like this:

java20.bat:

@echo off
call javaX "Java 20" %1Code language: DOS .bat (dos)

java20.ps1

javaX "Java 20" $args[0]
Code language: PowerShell (powershell)

javaX.bat:

@echo off

if %1 == "Java 1.2" set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.2.2
if %1 == "Java 1.3" set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.3.1_28
...
if %1 == "Java 20" set JAVA_HOME=C:\Program Files\Java\jdk-20
if %1 == "Java 21" set JAVA_HOME=C:\Program Files\Java\jdk-21

if "%~2" == "perm" (
  setx JAVA_HOME "%JAVA_HOME%" /M
)

set Path=%JAVA_HOME%\bin;%Path%

echo %~1 activated.Code language: DOS .bat (dos)

javaX.ps1:

param ($javaVersion, $perm)

switch ($javaVersion) {
  "Java 1.2" { $env:JAVA_HOME = "C:\Program Files (x86)\Java\jdk1.2.2" }
  "Java 1.3" { $env:JAVA_HOME = "C:\Program Files (x86)\Java\jdk1.3.1_28" }
  ...
  "Java 20" { $env:JAVA_HOME = "C:\Program Files\Java\jdk-20" }
  "Java 21" { $env:JAVA_HOME = "C:\Program Files\Java\jdk-21" }
}

if ($perm -eq "perm") {
  [Environment]::SetEnvironmentVariable("JAVA_HOME", $env:JAVA_HOME, [System.EnvironmentVariableTarget]::Machine)
}

$env:Path = $env:JAVA_HOME + '\bin;' + $env:Path

Write-Output "$javaVersion activated."
Code language: PowerShell (powershell)

In the files javaX.bat and javaX.ps1, you probably have to adjust some paths to the installed Java versions.

The scripts update the JAVA_HOME environment variable and insert 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 run Java commands such as java or javac.

(The Path variable gets longer with each change. Do not worry about it. This only affects the currently opened command line.)

Step 4: Add the Script Directory to the Path

To be able to call the scripts from anywhere, you have to add the directory to the «Path» environment variable (just like you did with «%JAVA_HOME%\bin» in the second step):

Adding "C:\Program Files\Java\scripts" to the "Path" system variable
Adding «C:\Program Files\Java\scripts» to the «Path» system variable

If you have installed the latest releases of all Java versions, you can use the scripts without any further adjustments. Open a new command line or PowerShell and enter, for instance, the following commands:

Changing the Java version in PowerShell
Changing the Java version

If one of the commands does not activate the expected Java version, please check if the path in the javaX.bat and javaX.ps1 files corresponds to the installation path of the Java version you want to activate.

Temporary and Permanent Java Version Changes

The commands presented up to this point only affect the currently opened command line or PowerShell. As soon as you open another command line, the default version defined in step 2 is active again (Java 20, if you have not changed anything).

If you want to change the Java version permanently, just add the parameter «perm» to the corresponding command, e.g.

java20 perm

Attention: To set the Java version permanently, you must open the command line or PowerShell as an administrator. Otherwise, you will get 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:

Were you able to follow the steps well – or do you have unanswered questions?

Either way, let me know by leaving a comment below.

I have done the following:

1. Set the environment variable JAVA_HOME:
enter image description here

2. Add Java 1.6.0_45 and disable Java 1.8.0_66 in Java Runtime Environment Settings under Configure Java:
enter image description here

Unfortunately, the Java is still 1.8.0_66:

>java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

Could anyone offer a tip on this?

Edit:

Per David’s suggestion, the following is the Java related contents from the output of command PATH (the entire output is super long, I hope the following is sufficient for this question.):

PATH=C:\ProgramData\Oracle\Java\javapath; ... C:\Program Files\Java\jdk1.6.0_45\bin

I’m working on few projects and some of them are using different JDK. Switching between JDK versions is not comfortable. So I was wondering if there is any easy way to change it?

I found 2 ways, which should solve this problem, but it doesn’t work.

First solution is creating a bat files like this:

@echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_72
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.7.0_72\bin;%PATH%
echo Display java version
java -version
pause

And after running this bat, I see right version of Java. But when I close this CMD and open a new one and type «java -version» it says that I still have 1.8.0_25. So it doesn’t work.

Second solution which I found is an application from this site. And it also doesn’t work. The same effect as in the first solution.

Any ideas? Because changing JAVA_HOME and PAHT by: Win + Pause -> Advanced System Settings -> Environment Variables -> and editing these variables, is terrible way…

asked Nov 18, 2014 at 11:22

Lui's user avatar

2

The set command only works for the current terminal. To permanently set a system or user environment variable you can use setx.

You can set the variable for the current user like this:

setx JAVA_HOME "C:\Program Files\Java\jdk1.7.0_72"

You can also set the variable system wide (Note: The terminal must be run as administrator fo this) by running the same command with the /m option:

setx JAVA_HOME "C:\Program Files\Java\jdk1.7.0_72" /m

The variable will be available in all new terminal session, but not the current one. If you also want to use the path in the same sessoin, you need to use both set and setx.

You can avoid manipulating the PATH variable if you just once put %JAVA_HOME% in there, instead of the full JDK path. If you change JAVA_HOME, PATH will be updated too.


There are also a few environment variable editors as alternative to the cumbersome Windows environment variable settings. See «Is there a convenient way to edit PATH in Windows 7?» on Super User.

answered Nov 18, 2014 at 11:29

kapex's user avatar

kapexkapex

29k6 gold badges107 silver badges121 bronze badges

8

In case if someone want to switch frequently in each new command window then I am using following approach.

Command Prompt Version:

Create batch file using below code. You can add n number of version using if and else blocks.

@echo off
if "%~1" == "11" (
   set "JAVA_HOME=C:\Software\openjdk-11+28_windows-x64_bin\jdk-11"
) else (
   set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_151"
)
set "Path=%JAVA_HOME%\bin;%Path%"
java -version

Save this batch file as SJV.bat and add this file location in your machine’s Path environment variable. So now SJV will act as command to «Switch Java Version».

Now open new command window and just type SJV 11 it will switch to Java 11.
Type SJV 8 it will switch to Java 8.

PowerShell Version

Create powershell(ps1) file using below code. You can add n number of version using if and else blocks.

If($args[0] -eq "11")
{
    $env:JAVA_HOME = 'C:\Software\openjdk-11+28_windows-x64_bin\jdk-11'
}else{
    $env:JAVA_HOME = 'C:\Program Files\Java\jdk1.8.0_151'
}
$env:Path = $env:JAVA_HOME+'\bin;'+$env:Path
java -version

Save this script file as SJV.ps1 and add this file location in your machine’s Path environment variable. So now SJV will act as command to «Switch Java Version».

Now open new powershell window and just type SJV 11 it will switch to Java 11.
Type SJV 8 OR SJV it will switch to Java 8.

I hope this help someone who want to change it frequently.

answered Oct 21, 2020 at 8:14

Prakash Boda's user avatar

4

  1. Open Environment Variables editor (File Explorer > right click on
    This PC > Properties > Advanced system settings > Environment
    Variables…)
  2. Find Path variable in System variables list >
    press Edit > put %JAVA_HOME%bin; at first position. This is required
    because Java installer adds C:\Program Files (x86)\Common
    Files\Oracle\Java\javapath
    to the PATH which references to the latest Java version installed. enter image description here
  3. Now you can switch between Java version using setx command (should be run under administrative permissions):

    setx /m JAVA_HOME "c:\Program Files\Java\jdk-10.0.1\
    

    (note: there is no double quote at the end of the line and should not be or you’ll get c:\Program Files\Java\jdk-10.0.1\" in your JAVA_HOME variable and it breaks your PATH variable)

Solution with system variables (and administrative permissions) is more robust because it puts desired path to Java at the start of the resulting PATH variable.

answered Jul 6, 2018 at 19:58

Ilya Serbis's user avatar

Ilya SerbisIlya Serbis

21.3k7 gold badges87 silver badges75 bronze badges

If your path have less than 1024 characters can execute (Run as Administrator) this script:

@echo off 
set "JAVA5_FOLDER=C:\Java\jdk1.5.0_22"
set "JAVA6_FOLDER=C:\Java\jdk1.6.0_45"
set "JAVA7_FOLDER=C:\Java\jdk1.7.0_80"
set "JAVA8_FOLDER=C:\Java\jdk1.8.0_121"
set "JAVA9_FOLDER=C:\Java\jdk-10.0.1"
set "CLEAR_FOLDER=C:\xxxxxx"

(echo "%PATH%" & echo.) | findstr /O . | more +1 | (set /P RESULT= & call exit /B %%RESULT%%)
set /A STRLENGTH=%ERRORLEVEL%
echo path length = %STRLENGTH%
if %STRLENGTH% GTR 1024  goto byebye 

echo Old Path: %PATH%
echo =================== 
echo Choose new Java Version:
echo [5] JDK5
echo [6] JDK6 
echo [7] JDK7
echo [8] JDK8
echo [9] JDK10
echo [x] Exit

:choice 
SET /P C=[5,6,7,8,9,x]? 
for %%? in (5) do if /I "%C%"=="%%?" goto JDK_L5 
for %%? in (6) do if /I "%C%"=="%%?" goto JDK_L6
for %%? in (7) do if /I "%C%"=="%%?" goto JDK_L7 
for %%? in (8) do if /I "%C%"=="%%?" goto JDK_L8 
for %%? in (9) do if /I "%C%"=="%%?" goto JDK_L9
for %%? in (x) do if /I "%C%"=="%%?" goto byebye
goto choice 

@echo on
:JDK_L5  
set "NEW_PATH=%JAVA5_FOLDER%"
goto setPath

:JDK_L6  
@echo off 
set "NEW_PATH=%JAVA6_FOLDER%"
goto setPath

:JDK_L7  
@echo off 
set "NEW_PATH=%JAVA7_FOLDER%"
goto setPath

:JDK_L8  
@echo off 
set "NEW_PATH=%JAVA8_FOLDER%"
goto setPath

:JDK_L9  
@echo off 
set NEW_PATH = %JAVA9_FOLDER%

:setPath
Call Set "PATH=%%PATH:%JAVA5_FOLDER%=%CLEAR_FOLDER%%%"
Call Set "PATH=%%PATH:%JAVA6_FOLDER%=%CLEAR_FOLDER%%%"
Call Set "PATH=%%PATH:%JAVA7_FOLDER%=%CLEAR_FOLDER%%%"
Call Set "PATH=%%PATH:%JAVA8_FOLDER%=%CLEAR_FOLDER%%%"
Call Set "PATH=%%PATH:%JAVA9_FOLDER%=%CLEAR_FOLDER%%%"
rem echo Interim Path: %PATH%
Call Set "PATH=%%PATH:%CLEAR_FOLDER%=%NEW_PATH%%%" 

setx PATH "%PATH%" /M

call set "JAVA_HOME=%NEW_PATH%"
setx JAVA_HOME %JAVA_HOME% 

echo New Path: %PATH%
:byebye
echo
java -version
pause

If more than 1024, try to remove some unnecessary paths, or can modify this scripts with some inputs from https://superuser.com/questions/387619/overcoming-the-1024-character-limit-with-setx

answered May 15, 2018 at 9:03

Conete Cristian's user avatar

Adding to the answer provided here (https://stackoverflow.com/a/64459399/894565).

I manually created environment variables via UI for Java11, Java17 and Java8. To change across Java version:

From powershell (PJV.ps1):

if($args[0] -eq "11") {
   $Env:JAVA_HOME="$ENV:JAVA11"
   $Env:Path="$Env:JAVA_HOME\bin;$Env:Path"
} elseif($args[0] -eq "17") {
   $Env:JAVA_HOME="$ENV:JAVA17"
   $Env:Path="$Env:JAVA_HOME\bin;$Env:Path"
} elseif($args[0] -eq "8") {
   $Env:JAVA_HOME="$ENV:JAVA8"
   $Env:Path="$Env:JAVA_HOME\bin;$Env:Path"
}
set "Path=%JAVA_HOME%\bin;%Path%"
java -version

From command line (JV.bat):

@echo off
if "%~1" == "11" (
   set "JAVA_HOME=%JAVA11%"
   setx JAVA_HOME "%JAVA11%"
) else if "%~1" == "17" (
   set "JAVA_HOME=%JAVA17%"
   setx JAVA_HOME "%JAVA17%"
) else (
   set "JAVA_HOME=%JAVA8%"
   setx JAVA_HOME "%JAVA8%"
)
set "Path=%JAVA_HOME%\bin;%Path%"
java -version

Finally both these files are in the same folder. And this folder path has been added to my system PATH

enter image description here

answered May 26, 2022 at 8:48

Jatin's user avatar

JatinJatin

31.2k15 gold badges98 silver badges164 bronze badges

Run this BAT file to conveniently change the java version.

Pros:

  1. It does NOT modify the PATH system environment variable.
  2. The only thing that has to be maintained is the relational array (can be conveniently constructed as a sparse array) that holds the version number and the path at the beginning of the script.

Precondition:

The following entry %JAVA_HOME%\bin has to be appended to the PATH environment variable.

@echo off
@cls
@title Switch Java Version
setlocal EnableExtensions DisableDelayedExpansion

:: This bat file Switches the Java Version using the JAVA_HOME variable.
:: This script does NOT modify the PATH system environment variable.
:: Precondition: The following entry "%JAVA_HOME%\bin" has to be appended to the PATH environment variable.
::  Script Name: SwitchJavaVersion | Version 1 | 2021/11/04

rem Add items to vector as follows:
rem   AvailableVersions["Java Major Version Number"]="Java Absolute Path"
set AvailableVersions[8]="D:\Program Files\Java\jdk8u252-b09"
set AvailableVersions[17]="D:\Program Files\Java\jdk-17.0.1"

call :PrintJavaVersion
call :PrintAvailableVersions
call :GetJavaVersion
call :SetJavaVersion
call :ResetLocalPath
if %errorlevel% neq 0 exit /b %errorlevel%
call :PrintJavaVersion

pause
endlocal
exit /b


rem Print available versions.
:PrintAvailableVersions
    echo Available Java Versions:
    for /f "tokens=2 delims=[]" %%I in ('set AvailableVersions[') do echo ^> %%I
    exit /b

rem Get version from user input or command-line arguments.
:GetJavaVersion
    set "JavaVersion="
    if "%~1"=="" (
        set /p JavaVersion="Type the major java version number you want to switch to: "
    ) else (
        set /a JavaVersion="%~1"
    )
    exit /b


rem Update JAVA_HOME user variable with hardcoded paths.
:SetJavaVersion
    set JavaPath=
    for /f "tokens=2 delims=[]" %%I in ('set AvailableVersions[') do (
        if "%%I" == "%JavaVersion%" (
            setlocal EnableDelayedExpansion
            set JavaPath=!AvailableVersions[%%I]!
            setlocal EnableExtensions DisableDelayedExpansion
        )
    )

    if not defined JavaPath (
        echo "Specified version NOT found: Default settings applied."
        for /f "tokens=2 delims==" %%I in ('set AvailableVersions[') do (
            set JavaPath=%%I
            goto exitForJavaPath
        )
        
    )
    :exitForJavaPath

    rem remove quotes from path
    set JavaPath=%JavaPath:"=%
    set "JAVA_HOME=%JavaPath%"
    setx JAVA_HOME "%JAVA_HOME%"
    
    rem setlocal statement was run 2 times previously inside the for loop; therefore, the endlocal statement must be executed 2 times to close those nested local scopes.

    
    rem below endlocal statement will close local scope set by previous "setlocal EnableExtensions DisableDelayedExpansion" statement
    endlocal & set "JavaPath=%JavaPath%"
    rem JAVA_HOME's value rolls back due to endlocal statement so the appropriate value has to be reassigned
    set "JAVA_HOME=%JavaPath%"
    rem below endlocal statement will close local scope set by previous "setlocal EnableDelayedExpansion" statement
    endlocal & set "JavaPath=%JavaPath%"
    rem JAVA_HOME's value rolls back due to endlocal statement so the appropriate value has to be reassigned
    set "JAVA_HOME=%JavaPath%"
    
    exit /b


rem Get User and System Path variable's definition from Registry,
rem    evaluate the definitions with the new values and reset
rem    the local path variable so newly set java version
rem    is properly displayed.
:ResetLocalPath
    set "PathValue="
    for /F "skip=2 tokens=1,2,*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /V Path') do if /I "%%I" == "Path" if not "%%~K" == "" if "%%J" == "REG_SZ" (set "PathValue=%%~K") else if "%%J" == "REG_EXPAND_SZ" call set "PathValue=%%~K"

    if not defined PathValue goto pathError

    set "UserPathValue="
    for /F "skip=2 tokens=1,2,*" %%I in ('%SystemRoot%\System32\reg.exe QUERY "HKCU\Environment" /V Path') do if /I "%%I" == "Path" if not "%%~K" == "" if "%%J" == "REG_SZ" (set "UserPathValue=%%~K") else if "%%J" == "REG_EXPAND_SZ" call set "UserPathValue=%%~K"

    if not defined UserPathValue goto pathError
    
    call set "Path=%PathValue%;%UserPathValue%"

    echo Path variable reset:
    echo PATH=%Path%  
    echo.
    exit /b


rem Display the Java version.
:PrintJavaVersion
    echo Current Java Version:
    java -version
    echo.
    exit /b


rem Error handling subroutine.
:pathError
    echo.
    echo Error while refreshing the PATH variable:
    echo PathValue=%PathValue%
    echo UserPathValue=%UserPathValue%
    pause
    exit /b 2

endlocal
exit

answered Nov 5, 2021 at 4:22

CamelCamelius's user avatar

Load below mentioned PowerShell script at the start of the PowerShell. or generate the file using New-Item $profile -Type File -Force
this will create a file here C:\Users\{user_name}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile

Now copy-paste the content given below in this file to be loaded each time the PowerShell is started

Set all the java versions you need as separate variables.

  1. Java_8_home-> Points to Java 8 Location in local
  2. Java_11_home -> Points to Java 11 Location in local
  3. Java_17_home -> Points to Java 17 Location in local
  4. Java_Home-> This points to the java version you want to use

Run in power shell to update the version to 8 update_java_version 8 $True

To update execution policy to allow script to be loaded at start of the PowerShell use below command
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force

`

function update_java_version($version, [bool] $everywhere)
{
    switch ($version)
    {
        8 {
            $java_value = (Get-Item Env:Java_8_home).value
            $Env:Java_Home = $java_value
            refresh-path
            break
        }
        11 {
            $java_value = (Get-Item Env:Java_11_home).value
            $Env:Java_Home = $java_value
            refresh-path
            break
        }
        17 {
            $java_value = (Get-Item Env:Java_17_home).value
            $Env:Java_Home = $java_value
            refresh-path
            break
        }
        default {
            throw "No matching java version found for `$version`: $version"
        }
    }
    if ($everywhere)
    {
        [System.Environment]::SetEnvironmentVariable("Java_Home", $java_value, "User")
    }
}

function refresh-path
{
    $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") +
            ";" +
            [System.Environment]::GetEnvironmentVariable("Path", "User")
}

answered Jan 4, 2022 at 8:51

Kid101's user avatar

Kid101Kid101

1,45011 silver badges25 bronze badges

change java version windows Examples

Hello, everyone! In this post, we will investigate how to discover the answer to change java version windows Examples using the computer language.

-vm C:\Program Files\Java\jre1.8.0_91\bin\javaw.exe

There are a variety of approaches that can be taken to solve the same problem change java version windows Examples. The remaining options will be discussed further down.

-vm
C:\Program Files\Java\jre1.8.0_91\bin\javaw.exe
-startup
plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.300.v20150602-1417
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm 
C:\Program Files\Java\jre1.8.0_91\bin\javaw.exe
-vmargs
-Dosgi.requiredJavaVersion=1.7
-Xms256m
-Xmx1024m

With numerous examples, we have seen how to resolve the change java version windows Examples problem.

How do I change Java version to 11 on Windows?

Enable the latest installed version of Java in the Java Control Panel

  • In the Java Control Panel, click on the Java tab.
  • Click View to display the Java Runtime Environment Settings.
  • Verify that the latest Java Runtime version is enabled by checking the Enabled box.
  • Click OK to save settings.

How do I change Java version in Windows command line?

7 Answers

  • Start -> Control Panel -> System -> Advanced.
  • Click on Environment Variables, under System Variables, find PATH, and click on it.
  • In the Edit windows, modify PATH by adding the location of your jdk5/bin directory to the beginning.
  • Close the window.
  • Reopen Command prompt window, and run java -version.

How can I change Java 8 to 11?

Steps to migrate from jdk-8 to openJDK-11.md

  • upgrade build tools.
  • Add missing Java dependencies in jdk11.
  • Remove findbug and add Spotbugs.
  • Changes in GC options. Runtime GC log changes. GC info.
  • Fork-join Thread pool.
  • Class-Loader.
  • IDE-setup.

How do I downgrade to Java 8 on Windows?

Information

  • Access the Control Panel: In Windows 10 click in the search box on the bottom left corner of task bar (either Cortana or the magnifying glass) and type Control Panel.
  • Select Programs and Features.
  • In the list of programs, select the undesired version of Java, then click Uninstall.

How do I switch Java versions?

How to Change Java Versions in Windows (Updated for Java 19)

  • Step 1: Installing Multiple Java Versions. Installing multiple Java versions in parallel is incredibly easy in Windows.
  • Step 2: Define Java Environment Variables.
  • Step 3: Install the Scripts to Change the Java Version.
  • Step 4: Add the Script Directory to the Path.

Can I have Java 11 and Java 8?

I know you can install both. Java 8 and Java 11 and keep them at the same time03-Aug-2020

Can I Update Java from cmd?

Right-click Command Prompt in the Programs list. In the Java Control Panel, click on the Update tab.

How do I change Java options in Windows 10?

Starting with Java 7 Update 40, you can find the Java Control Panel through the Windows Start menu.

  • Launch the Windows Start menu.
  • Click on Programs (All Apps on Windows 10)
  • Find the Java program listing.
  • Click Configure Java to launch the Java Control Panel.

Can I have 2 Java versions installed?

It is very possible to run multiple versions of Java on the same machine so you can run your existing applications and Ignition at the same time.22-Dec-2021

Is Java 11 and 1.8 the same?

It is an open-source reference implementation of Java SE platform version 11. Java 11 was released after four years of releasing Java 8. Java 11 comes with new features to provide more functionality. Below are the features which are added in the four and a half years in between these two versions.

Solution 1

java -version is running the wrong version of java.

Diagnostics:

>java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

the following is the Java related contents from the output of PATH:

PATH=C:\ProgramData\Oracle\Java\javapath; ... C:\Program Files\Java\jdk1.6.0_45\bin

Conclusion:

From the above output we can deduce that C:\ProgramData\Oracle\Java\javapath is 1.8.0_66.

You need to change your PATH to put C:\Program Files\Java\jdk1.6.0_45\bin first.

I noticed that after checking the path per your suggestion. Windows 10 does not allow me to edit the path because it says «This environment variable is too large.» I know there should be another question to deal with this separately.

You also need to clean up your path. My guess is you have a lot of duplicate entries.

Solution 2

I have the same problem, I have set JAVA_HOME:

C:\Program Files\Java\jdk1.7.0_75

and Path to:

%JAVA_HOME%\bin

I need run jdk 7. When I run java -version it always appear jdk 8.

I solved it with: in System Environment —> Path —> order %JAVA_HOME%\bin to first.

Solution 3

This is the REAL active JAVA executable into your PATH:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath;

Remove it and the system take the value from

...;%JAVA_HOME%\bin\;

Solution 4

Check also registry. Press Win key-R, type regedit. Search for Computer\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment. If there is something different, than you expect, than it is better to reinstall Java. If it not possible, very carefully change the settings. Be aware, that from version to version the setup can be different. In my case I would to downgrade from Java 1.9 to 1.8.

Java Registry Setup

Solution 5

enter image description here

As you can check the javapath variable under system’s environment path variable.

So if you want to use your own version.You can do

  • 1) Create new variable in systems variable
  • 2) Name it as JAVA_HOME and give jdk installation path
  • 3) add this variable in path and move it to top.
  • 4) check java -version

you need to create a JAVA_HOME

Related videos on Youtube

How To Download And Install Java on Windows 10 ( Java JDK on Windows 10) + Set JAVA_HOME

08 : 56

How To Download And Install Java on Windows 10 ( Java JDK on Windows 10) + Set JAVA_HOME

How to keep Multiple Java versions in Windows 10

02 : 02

How to keep Multiple Java versions in Windows 10

Easily Switch between different JDK versions - in Windows | The perfect workstation setup for a

03 : 26

Easily Switch between different JDK versions — in Windows | The perfect workstation setup for a

How to switch between the multiple Java versions(JDK) in windows 10 | Switch between java 8,11,15,17

02 : 19

How to switch between the multiple Java versions(JDK) in windows 10 | Switch between java 8,11,15,17

How to switch multiple Java versions in Windows the Easy Way

04 : 08

How to switch multiple Java versions in Windows the Easy Way

Comments

  • I have done the following:

    1. Set the environment variable JAVA_HOME:
    enter image description here

    2. Add Java 1.6.0_45 and disable Java 1.8.0_66 in Java Runtime Environment Settings under Configure Java:
    enter image description here

    Unfortunately, the Java is still 1.8.0_66:

    >java -version
    java version "1.8.0_66"
    Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
    Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)
    

    Could anyone offer a tip on this?

    Edit:

    Per David’s suggestion, the following is the Java related contents from the output of command PATH (the entire output is super long, I hope the following is sufficient for this question.):

    PATH=C:\ProgramData\Oracle\Java\javapath; ... C:\Program Files\Java\jdk1.6.0_45\bin
    

    • Please edit and include the output of path in a cmd shell.

    • @DavidPostill I have just done it following your suggestion. Thank you.

    • C:\ProgramData\Oracle\Java\javapath will be 1.8.0_66. Put C:\Program Files\Java\jdk1.6.0_45\bin first.

    • Note that changes to environment variables may not be fully applied until you sign in again. Reboot and try java -version again.

    • @DavidPostill I noticed that after checking the path per your suggestion. Windows 10 does not allow me to edit the path because it says «This environment variable is too large.» I know there should be another question to deal with this separately.

    • Have you tried to put just ´%JAVA_HOME%\bin´ instead ´C:\Program Files\Java\jdk1.6.0_45\bin´

    • @Hong «This environment variable is too large» — you need to clean up your path. My guess is you have a lot of dupe entries.

    • @DavidPostill I managed to delete «C:\ProgramData\Oracle\Java\javapath» and put «%JAVA_HOME%\bin» first. Now Java -version returns «1.6.0_45». The PATH command returns «C:\Program Files\Java\jdk1.6.0_45\bin;» as the first. Could you turn your comment to an Answer so that I can accept and close this question?

    • @Stackcraft_noob ´C:\Program Files\Java\jdk1.6.0_45\bin´ was actually the result of ´%JAVA_HOME%\bin´ that I added to the user (not system) variable PATH. Now I have moved it to the system PATH.

    • @gronostaj I have noticed that I need to restart CMD, not the computer, after changing the environment.

    • @Stackcraft_noob thanks for the tip, for me, the windows didn’t want to recognize the ´C:\Program Files\Java\jdk1.6.0_45\bin´, but did accept ´%JAVA_HOME%\bin´

    • I would remove javapath from PATH and add the actual java version directory directly. This allows easy switching without the need to maintain the registry. Note that this is not true for in-Browser Java.

  • Order changing doesn’t help, java -version is always 8. My configuration: Windows 10 with jdk 8 installed alongside jdk 7.

  • @naXa Please ask your own question, supplying the appropriate information.

  • This answer is correct

  • No, it’s not a «REAL» java! It’s the oracle’s way to redirect the «java.exe», etc. simple executions to the «REAL» java installation, which is specified in Computer\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment So this solution is replacing the registry-based indirection (managed by java installers) with the Environment-variable based indirection (managed by theuser). See also: stackoverflow.com/a/51457823/849897

  • This is the correct answer !! Thank you very much !!

  • I had to restart my computer before it worked.

  • After hours of experimenting with the environment variables and the java config settings in VS Code, this finally made it clear what actually determined which version of java was running… thank you

  • With old java installers a java.exe is often present in c:\Windows\System32 the classic headache!

Recents

Related

  • How to change interface language in windows 10
  • How to change fonts in windows 10
  • Hotline miami 2 wrong number не запускается на windows 10
  • How to change account name windows 10
  • How to change font in windows 10