Oftentimes you find that there are different SDK requirements for different projects. A classic example would be that your Scala project might be stuck at JDK 8 level1, but Java projects themselves might be using later versions, such as JDK 11.
It would be cumbersome to switch between different JDK versions manually, having
to make sure to correctly setup
JAVA_HOME when you switch between projects.
sdkman is there to address this problem and the same class
of problems for other types of development setups as well. These include Scala,
Groovy, Gradle and a lot more.
Installation and setup
Follow the instructions to install sdkman.
The installation script integrates to bash/zsh automatically. You can alternatively add the following at the end of the ~/.bashrc or ~/.zshrc for bash and zsh respectively.
export SDKMAN_DIR="$HOME/.sdkman" [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
SDKMAN_DIR is the default location for the install and on a POSIX system it is
Default location can be customised by exporting
$SDKMAN_DIR variable to a
custom location, as shown below,
export SDKMAN_DIR="/usr/local/sdkman" && curl -s "https://get.sdkman.io" | bash`
Integration with fish shell
Fish shell, which is my current shell, requires a third party plugin, or manual setup. I found that sdkman-for-fish works quite nicely. This plugin adds sdkman binaries to fish path and also adds autocompletion for sdkman commands.
To install for fish shell with the popular fisher2 tool run
fisher add reitzig/sdkman-for-fish
Usage is illustrated in following examples in terms of Java SDKs, but adapting the same commands for other SDKs should be quite simple given they follow the same usage patterns.
To see a list of all available SDK types,
To get a list of available Java sdk versions,
sdk list java
To install a version of Java, after selecting a version using the above command,
sdk install java 8.0.232.hs-adpt
To remove sdk version,
sdk rm java 8.0.232.hs-adpt
uninstallalso works in place of
How to change the default version globally,
sdk default java 11.0.5.hs-adpt
Using a specific version for a specific shell session without changing the default globally,
sdk use java 8.0.232.hs-adpt
Where to find the installed SDKs?
Candidates for a given SDK is found under the
candidates directory in
$SDKMAN_DIR. For example, in Java SDKs,
Location for JDK 11 from OpenJDK,
Specific version locations are useful for setting up project specific JDKs in IDEs.
Current version is a symbolic link to one of the instlaled candidates,
It is useful to set the
JAVA_HOME environment variable to always point to the
For bash/zsh shells,
For fish shell,
set -g -x JAVA_HOME '$SDKMAN_DIR/candidates/java/current'