JavaVersionManager is a lightweight PowerShell module for managing multiple installed Java versions on Windows. It allows you to list configured Java versions and easily switch between them by updating the JAVA_HOME environment variable and adjusting the PATH for the current session.
- List installed Java versions
- Display the currently active Java version
- Switch Java version in the current terminal session
- Optional output of the full Java binary path
Install-Module -Name JavaVersionManager -Scope CurrentUserThen import it:
Import-Module JavaVersionManagerImport-Module ./JavaVersionManager.psm1Before using the module, you must define the available Java versions on your machine using a global hashtable. This should be done in your PowerShell profile (e.g., Microsoft.PowerShell_profile.ps1).
# JAVA VERSION MANAGER
if (-not $Global:JavaVersions) {
$Global:JavaVersions = @{
jdk8 = 'C:\Program Files\Java\jdk1.8.0_211'
jdk11 = 'C:\Program Files\Java\jdk-11.0.27'
jdk17 = 'C:\Program Files\Java\jdk-17.0.15'
jdk22 = 'C:\Program Files\Java\jdk-22.0.2'
}
}Lists all installed Java versions and highlights the one currently in use.
-IncludePathBinary– Optional. Shows the full path to the Java binary.-Target– Optional. Specifies which environment scope to read (Process,User, orMachine). Default:Process.
Get-JavaVersion
Get-JavaVersion -IncludePathBinary
Get-JavaVersion -Target MachineSets the desired Java version by updating the JAVA_HOME environment variable and modifying the PATH for the current session.
-Version– The Java version to set (must exist in$Global:JavaVersions).-Target– Optional. Defines the environment scope to update. Default:Process.
Set-JavaVersion jdk22
Set-JAvaVersion jdk17 -Target Machine- Windows 10 or 11
- PowerShell 5.1+ or PowerShell Core
$Global:JavaVersionsconfigured as shown above
This project is licensed under CC BY-NC-SA 4.0