Manage Java versions with SDKMan
Seth Kenlon
Tue, 03/15/2022 - 02:01
Up
Register or
Login to like.
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.
More on Java
What is enterprise Java programming?
Red Hat build of OpenJDK
Java cheat sheet
Free online course: Developing cloud-native applications with microservices arc…
Fresh Java articles
Install SDKMan
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
On Debian-based distributions, use apt instead of dnf. On macOS, use MacPorts or Homebrew. On Windows, you can use SDKMan through Cygwin or WSL.
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
$ ./sdkman.shConfigure
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 versionInstall 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 | 22.0.0.3.r17 | gln | 22.0.0.3.r17-gln
| 22.0.0.3.r11 | gln | 22.0.0.3.r11-gln
GraalVM | 22.0.0.2.r17 | grl | 22.0.0.2.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 Identifier column:
$ sdk install java 11.0.12-open
The 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 javaSet your current version of Java
Set the version of Java for a terminal session with the use subcommand:
$ sdk use java 17.0.2-open
To set a version as default, use the default subcommand:
$ sdk default java 17.0.2-open
Get the current version in effect using the current subcommand:
$ sdk current java
Using java version 17.0.2-openRemoving Java with SDKMan
You can remove an installed version of Java using the uninstall subcommand:
$ sdk uninstall java 11.0.12-openMore SDKMan
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!
The SDKMan project makes it easy to manage different versions of Java and related languages, including Groovy, Scala, Kotlin, and more.
Image by:
Image by WOCinTech Chat, CC BY 2.0
Java
What to read next
This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.
6482 points
(Correspondent)
Vancouver, Canada
Seldom without a computer of some sort since graduating from the University of British Columbia in 1978, I have been a full-time Linux user since 2005, a full-time Solaris and SunOS user from 1986 through 2005, and UNIX System V user before that.
On the technical side of things, I have spent a great deal of my career as a consultant, doing data analysis and visualization; especially spatial data analysis. I have a substantial amount of related programming experience, using C, awk, Java, Python, PostgreSQL, PostGIS and lately Groovy. I'm looking at Julia with great interest. I have also built a few desktop and web-based applications, primarily in Java and lately in Grails with lots of JavaScript on the front end and PostgreSQL as my database of choice.
Aside from that, I spend a considerable amount of time writing proposals, technical reports and - of course - stuff on https://www.opensource.com.
Open Sourcerer
People's Choice Award
100+ Contributions Club
Emerging Contributor Award 2016
Author
Comment Gardener
Correspondent
Columnist
Contributor Club
Register or
Login to post a comment.