What is SDKMAN!

SDKMAN! is a development tool that allows you to install and manage Java, Scala, Groovy, Maven and many other tools, libraries and programming languages united under JVM platform. It is created for GNU/Linux’s and MacOS’ users.

Installation

The first step is to paste this command in your terminal and submit it.

curl -s "https://get.sdkman.io" | bash

This will launch the process of installation, which might require your input. After successful installation paste this command and you are ready to work.

source "$HOME/.sdkman/bin/sdkman-init.sh"

Usage

You can list all available versions of desired SDK using below command:

sdk list <sdk>

Here is output of this command for Groovy.

sdk list groovy

================================================================================
Available Groovy Versions
================================================================================
     3.0.0-beta-3        2.4.8               2.1.4               1.7.6          
     3.0.0-beta-2        2.4.7               2.1.3               1.7.5          
     3.0.0-beta-1        2.4.6               2.1.2               1.7.4          
     3.0.0-alpha-4       2.4.5               2.1.1               1.7.3          
     3.0.0-alpha-3       2.4.4               2.1.0               1.7.2          
     3.0.0-alpha-2       2.4.3               2.0.8               1.7.1          
     3.0.0-alpha-1       2.4.2               2.0.7               1.7.0          
     2.6.0-alpha-4       2.4.1               2.0.6               1.6.9          
     2.6.0-alpha-3       2.4.0               2.0.5               1.6.8          
     2.6.0-alpha-2       2.3.11              2.0.4               1.6.7          
     2.6.0-alpha-1       2.3.10              2.0.3               1.6.6          
     2.5.8               2.3.9               2.0.2               1.6.5          
     2.5.7               2.3.8               2.0.1               1.6.4          
     2.5.6               2.3.7               2.0.0               1.6.3          
     2.5.5               2.3.6               1.8.9               1.6.2          
     2.5.4               2.3.5               1.8.8               1.6.1          
     2.5.3               2.3.4               1.8.7               1.6.0          
     2.5.2               2.3.3               1.8.6               1.5.8          
     2.5.1               2.3.2               1.8.5               1.5.7          
     2.5.0               2.3.1               1.8.4               1.5.6          
     2.4.17              2.3.0               1.8.3               1.5.5          
     2.4.16              2.2.2               1.8.2               1.5.4          
     2.4.15              2.2.1               1.8.1               1.5.3          
     2.4.14              2.2.0               1.8.0               1.5.2          
     2.4.13              2.1.9               1.7.11              1.5.1          
     2.4.12              2.1.8               1.7.10              1.5.0          
     2.4.11              2.1.7               1.7.9                              
     2.4.10              2.1.6               1.7.8                              
     2.4.9               2.1.5               1.7.7                              

================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

Installation is effortless. Select any of available versions or just skip it and install the currently stable version.

sdk install <sdk> (<version>)

Let’s try install Java 11. Paste sdk install java 11.0.4-hs-adpt and hit Enter.

sdk install java 11.0.4.hs-adpt

Downloading: java 11.0.4.hs-adpt

In progress...

######################################################################## 100,0%

Repackaging Java 11.0.4.hs-adpt...

Done repackaging...

Installing: java 11.0.4.hs-adpt
Done installing!

Do you want java 11.0.4.hs-adpt to be set as default? (Y/n): 

Setting java 11.0.4.hs-adpt as default.

All installed Java versions will be available in the folder $SDKMAN_DIR/candiadates/java.

ls $SDKMAN_DIR/candidates/java -l
total 8
drwxr-xr-x.  9 wpanas wpanas 4096 10-18 17:44 8u152-zulu
drwxr-xr-x. 10 wpanas wpanas 4096 11-04 16:22 9.0.1-zulu
lrwxrwxrwx.  1 wpanas wpanas   47 12-25 17:23 current -> /home/wpanas/.sdkman/candidates/java/11.0.4.hs-adpt

You can check if installation was successful by checking current Java version. The command java --version will not work in Java 8 or any previous, so let’s try it.

java --version
openjdk 11.0.4 2019-07-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.4+11, mixed mode)

As you can see Java 11 is installed and ready to work. If you want to switch default Java’s version use command sdk default java <version>, but you can also switch version only for current terminal session using sdk use java <version>. It’s very convenient, if you want to check, how your code would behave on different Java version.

Summary

SDKMAN! is an essential tool for developers using Java, Groovy or any other JVM language. Check it out and you will not be disappointed.