Java is more than just a programming language: It's also a runtime.
Applications written in Java are compiled to Java bytecode then interpreted by a Java Virtual Machine (JVM), which is why you can write Java on one platform and have it run on all other platforms.
A challenge can arise, however, when a programming language and an application develop at different rates. It's possible for Java (the language) to increment its version number at the same time your favorite application continues to use an older version, at least for a while.
If you have two must-have applications, each of which uses a different version of Java, you may want to install both an old version and a new version of Java on the same system. If you're a Java developer, this is particularly common, because you might contribute code to several projects, each of which requires a different version of Java.
The SDKMan project makes it easy to manage different versions of Java and related languages, including Groovy, Scala, Kotlin, and more.
SDKMan is like a package manager just for versions of Java.
SDKMan requires these commands to be present on your system:
On Linux, you can install these using your package manager. On Fedora, CentOS Stream, Mageia, and similar:
$ sudo dnf install zip unzip curl sed
Once you've satisfied those requirements, download the SDKMan install script:
$ curl "https://get.sdkman.io" --output sdkman.sh
Take a look at the script to see what it does, and then make it executable and run it:
$ chmod +x sdkman.sh
When the installation has finished, open a new terminal, or run the following in the existing one:
$ source ~/.sdkman/bin/sdkman-init.sh
Confirm that it's installed:
$ sdk version
Install Java with SDKMan
Now when you want to install a version of Java, you can do it using SDKMan.
First, list the candidates for Java available:
$ sdk list java
Available Java Versions for Linux 64bit
Vendor | Version | Dist | Identifier
Gluon | 220.127.116.11.r17 | gln | 18.104.22.168.r17-gln
| 22.214.171.124.r11 | gln | 126.96.36.199.r11-gln
GraalVM | 188.8.131.52.r17 | grl | 184.108.40.206.r17-grl
| 21.3.1.r17 | grl | 21.3.1.r17-grl
| 20.3.5.r11 | grl | 20.3.5.r11-grl
| 19.3.6.r11 | grl | 19.3.6.r11-grl
Java.net | 19.ea.10 | open | 19.ea.10-open
| 18 | open | 18-open
| 17.0.2 | open | 17.0.2-open
| 11.0.12 | open | 11.0.12-open
| 8.0.302 | open | 8.0.302-open
This provides a list of different Java distributions available across several popular vendors, including Gluon, GraalVM, OpenJDK from Java.net, and many others.
You can install a specific version of Java using the value in the
$ sdk install java 11.0.12-open
sdk command uses tabbed completion, so you don't need to view a list. Instead you can type
sdk install java 11 and then press Tab a few times to get the options.
Alternately, you can just install the default latest version:
$ sdk install java
Set your current version of Java
Set the version of Java for a terminal session with the
$ sdk use java 17.0.2-open
To set a version as default, use the
$ sdk default java 17.0.2-open
Get the current version in effect using the
$ sdk current java Using java version 17.0.2-open
Removing Java with SDKMan
You can remove an installed version of Java using the
$ sdk uninstall java 11.0.12-open
You can do more customization with SDKMan, including updating and upgrading Java versions and creating project-based environments. It's a useful command for any developer or user who wants the ability to switch between versions of Java quickly and easily.
If you love Java, or use Java, give SDKMan a try. It makes Java easier than ever!