MyJavaManager is a PowerShell module to install, track and switch between Java versions on Windows.
- Download Java from Adoptium (Eclipse Temurin JDK), for the architecture of your system (x64 or ARM64)
- Keep track of your Java versions in an inventory (JSON file), including the ones you installed yourself
- Switch between Java versions in one command:
JAVA_HOMEandPathare updated, in the current console too - Remove a Java version, and optionally its directory, safely
Install-Module -Name MyJavaManager # Install the module from PowerShell Gallery
Invoke-DownloadJavaPackage -Version 21 # Download Java 21 and add it to the inventory
Get-JavaEntry # List the Java versions of the inventory
Switch-JavaVersion # Pick the Java version to use from a menu
java -version # Ready to use, right awayTable of contents:
The module is Windows-only (it relies on the Windows Registry and Windows APIs).
It supports the following PowerShell versions:
- Windows PowerShell 5.1
- PowerShell 6 and later, on Windows
Get the latest version of PowerShell from the official PowerShell repository.
The module is published on PowerShell Gallery. See https://www.powershellgallery.com/packages/MyJavaManager.
To install it, run:
Install-Module -Name MyJavaManager -Repository PSGalleryOn PowerShell 7.4 or later, you can also run Install-PSResource -Name MyJavaManager.
Download MyJavaManager.zip from the "Releases" page.
Extract it to your user modules directory:
- Windows PowerShell 5.1:
~\Documents\WindowsPowerShell\Modules\ - PowerShell 6 and later:
~\Documents\PowerShell\Modules\
-
Unblock downloaded scripts (optional)
Get-ChildItem -Filter *.ps1 | Unblock-File
-
Build the module
.\build.ps1 Build -Bootstrap -
Remove any old versions of the module
$ModulesDirectory = $env:PSModulePath.Split([System.IO.Path]::PathSeparator)[0] Remove-Item (Join-Path $ModulesDirectory "MyJavaManager") -Recurse -Force -ErrorAction SilentlyContinue
-
Install the freshly built module
Copy-Item ".\Out\MyJavaManager" $ModulesDirectory -Recurse
-
Import the module
Import-Module -Name MyJavaManager
-
Get the available commands
Get-Command -Module MyJavaManager
The fastest way to use the module is to import it from your PowerShell profile (run $PROFILE to get its path).
Then, each time you will open your PowerShell console, the module will be automatically imported.
Your Java versions are stored in the inventory file ~\MyJavaManager.json.
To download and install a Java package from Adoptium, use Invoke-DownloadJavaPackage.
Invoke-DownloadJavaPackage -Version 21- Without
-Version, a menu lets you pick the version (LTS versions are marked, e.g.21 (LTS)). In a non-interactive session, the latest LTS (Long-Term Support) version is downloaded. - The package is installed in
~\.java_packages, and an entry is added to the inventory. - The package matches the architecture of your system (x64 or ARM64). Adoptium provides Windows ARM64 packages for some Java versions only.
To add a Java version that you installed yourself, use Add-JavaEntry with the path to its Java home directory.
Add-JavaEntry -Path "C:\Program Files\Java\jdk-17"
Add-JavaEntry -Path "C:\Program Files\Java\jdk-17" -CustomName MyJava17The entry is named after the Java version (e.g. jdk-17.0.1.0), unless you give a custom name.
To use another Java version, use Switch-JavaVersion.
Switch-JavaVersion # Pick the Java version from a menu
Switch-JavaVersion -Name MyJava17 # Use a Java version of the inventory
Switch-JavaVersion -Path "C:\path\to\java_home_directory" # Use any Java home directoryIt sets the JAVA_HOME environment variable and adds %JAVA_HOME%\bin to the Path.
The current console is updated too, so you can use the new version right away.
The -Target parameter defines where the change is saved:
| Target | Description |
|---|---|
User |
For your user: the current console and new ones. (Default) |
Machine |
For all users: the current console and new ones. Requires administrator rights. |
Process |
For the current console only. |
To remove a Java version from the inventory, use Remove-JavaEntry.
Remove-JavaEntry -Name MyJava17
Remove-JavaEntry -Name jdk-11.0.13.0 -RemoveDirectory # Also remove its directory from the diskWith -RemoveDirectory, nothing is removed if the directory is not a Java home directory or if it is the current JAVA_HOME.
If other entries use the same directory, only the entry is removed.
| Command | Description |
|---|---|
Invoke-DownloadJavaPackage |
Downloads and installs a Java package from Adoptium, and adds it to the inventory. |
Add-JavaEntry |
Adds an existing Java installation to the inventory. |
Get-JavaEntry |
Gets the Java versions of the inventory. |
Switch-JavaVersion |
Switches the Java version in use (JAVA_HOME and Path). |
Remove-JavaEntry |
Removes a Java version from the inventory, and optionally its directory. |
Every command that changes something supports -WhatIf and -Confirm.
Read help files in docs/cmdlet-help.
You can also use the Get-Help Cmdlet to obtain more information about a command.
To build the module and run the tests (PSScriptAnalyzer and Pester), run:
.\build.ps1 Test -BootstrapRead docs/development for the docstrings, versioning and publishing guidelines.
MyJavaManager is released under the terms of the MIT license. See LICENSE or https://opensource.org/licenses/MIT.
If you have any bug reports, log them on the issue tracker.
If you have some suggestions, please don't hesitate to contact me (find email on my GitHub profile).