How to install multiple Java versions on Linux, MacOS, or WSL2?
Ever wondered how to install multiple Java (JDK) versions on your operating system? There is one tool that does it very well - SDKMAN.
Install SDKMAN
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
More instructions: https://sdkman.io/install
List available Java versions - sdk list
$ sdk list java
================================================================================
Available Java Versions
================================================================================
Vendor | Use | Version | Dist | Status | Identifier
--------------------------------------------------------------------------------
AdoptOpenJDK | | 15.0.1.j9 | adpt | | 15.0.1.j9-adpt
| | 15.0.1.hs | adpt | | 15.0.1.hs-adpt
| | 14.0.2.j9 | adpt | | 14.0.2.j9-adpt
| | 14.0.2.hs | adpt | | 14.0.2.hs-adpt
| | 13.0.2.j9 | adpt | | 13.0.2.j9-adpt
| | 13.0.2.hs | adpt | | 13.0.2.hs-adpt
| | 12.0.2.j9 | adpt | | 12.0.2.j9-adpt
| | 12.0.2.hs | adpt | | 12.0.2.hs-adpt
| | 11.0.9.open | adpt | | 11.0.9.open-adpt
| | 11.0.9.j9 | adpt | | 11.0.9.j9-adpt
| | 11.0.9.hs | adpt | | 11.0.9.hs-adpt
| | 8.0.272.open | adpt | | 8.0.272.open-adpt
| | 8.0.272.j9 | adpt | | 8.0.272.j9-adpt
| | 8.0.272.hs | adpt | | 8.0.272.hs-adpt
Alibaba | | 11.0.8 | albba | | 11.0.8-albba
| | 8u262 | albba | | 8u262-albba
Amazon | | 15.0.1 | amzn | | 15.0.1-amzn
| | 11.0.9 | amzn | | 11.0.9-amzn
| | 8.0.272 | amzn | | 8.0.272-amzn
Azul Zulu | | 15.0.1 | zulu | | 15.0.1-zulu
| | 15.0.1.fx | zulu | | 15.0.1.fx-zulu
| | 14.0.2 | zulu | | 14.0.2-zulu
| | 14.0.2.fx | zulu | | 14.0.2.fx-zulu
| | 13.0.5 | zulu | | 13.0.5-zulu
| | 13.0.5.fx | zulu | | 13.0.5.fx-zulu
| | 12.0.2 | zulu | | 12.0.2-zulu
| | 11.0.9 | zulu | | 11.0.9-zulu
| | 11.0.9.fx | zulu | | 11.0.9.fx-zulu
| | 10.0.2 | zulu | | 10.0.2-zulu
| | 9.0.7 | zulu | | 9.0.7-zulu
| | 8.0.272 | zulu | | 8.0.272-zulu
| | 8.0.272.fx | zulu | | 8.0.272.fx-zulu
| | 7.0.282 | zulu | | 7.0.282-zulu
| | 6.0.119 | zulu | | 6.0.119-zulu
BellSoft | | 15.0.1.fx | librca | | 15.0.1.fx-librca
| | 15.0.1 | librca | | 15.0.1-librca
| | 14.0.2.fx | librca | | 14.0.2.fx-librca
| | 14.0.2 | librca | | 14.0.2-librca
| | 13.0.2.fx | librca | | 13.0.2.fx-librca
| | 13.0.2 | librca | | 13.0.2-librca
| | 12.0.2 | librca | | 12.0.2-librca
| | 11.0.9.fx | librca | | 11.0.9.fx-librca
| | 11.0.9 | librca | | 11.0.9-librca
| | 8.0.272.fx | librca | | 8.0.272.fx-librca
| | 8.0.272 | librca | | 8.0.272-librca
| | 8.0.265.fx | librca | | 8.0.265.fx-librca
GraalVM | | 20.2.0.r11 | grl | | 20.2.0.r11-grl
| | 20.2.0.r8 | grl | | 20.2.0.r8-grl
| | 20.1.0.r11 | grl | | 20.1.0.r11-grl
| | 20.1.0.r8 | grl | | 20.1.0.r8-grl
| | 20.0.0.r11 | grl | | 20.0.0.r11-grl
| | 20.0.0.r8 | grl | | 20.0.0.r8-grl
| | 19.3.1.r11 | grl | | 19.3.1.r11-grl
| | 19.3.1.r8 | grl | | 19.3.1.r8-grl
Java.net | | 16.ea.21 | open | | 16.ea.21-open
| | 16.ea.6.lm | open | | 16.ea.6.lm-open
| | 16.ea.2.pma | open | | 16.ea.2.pma-open
| | 15.0.1 | open | | 15.0.1-open
| | 14.0.2 | open | | 14.0.2-open
| | 13.0.2 | open | | 13.0.2-open
| | 12.0.2 | open | | 12.0.2-open
| | 11.0.2 | open | | 11.0.2-open
| | 10.0.2 | open | | 10.0.2-open
| | 9.0.4 | open | | 9.0.4-open
| | 8.0.265 | open | | 8.0.265-open
SAP | | 15.0.0 | sapmchn | | 15.0.0-sapmchn
| | 14.0.2 | sapmchn | | 14.0.2-sapmchn
| | 13.0.2 | sapmchn | | 13.0.2-sapmchn
| | 12.0.2 | sapmchn | | 12.0.2-sapmchn
| | 11.0.8 | sapmchn | | 11.0.8-sapmchn
================================================================================
Use the Identifier for installation:
$ sdk install java 11.0.3.hs-adpt
================================================================================
Install specific Java version - sdk install
$ sdk install java 15.0.1.j9-adpt
Switch between different Java versions - sdk use
$ sdk use java 15.0.1.j9-adpt
List help page - sdk help
$ sdk help
Usage: sdk <command> [candidate] [version]
sdk offline <enable|disable>
commands:
install or i <candidate> [version] [local-path]
uninstall or rm <candidate> <version>
list or ls [candidate]
use or u <candidate> <version>
default or d <candidate> [version]
home or h <candidate> <version>
env or e [init]
current or c [candidate]
upgrade or ug [candidate]
version or v
broadcast or b
help
offline [enable|disable]
selfupdate [force]
update
flush <broadcast|archives|temp>
candidate : the SDK to install: groovy, scala, grails, gradle, kotlin, etc.
use list command for comprehensive list of candidates
eg: $ sdk list
version : where optional, defaults to latest stable if not provided
eg: $ sdk install groovy
local-path : optional path to an existing local installation
eg: $ sdk install groovy 2.4.13-local /opt/groovy-2.4.13