Are you a developer who often test applications on different SDKs? I've got a good news for you! SDKMAN is a CLI tool that helps you to easily manage multiple software development kits on Linux. It provides a convenient way to install, switch, list and remove candidates. Using SDKMAN, we can easily manage parallel versions of multiple SDKs. It allows the developers to install software development kits for the JVM such as Java, Groovy, Scala, Kotlin and Ceylon. Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x and many others are also supported. SDKMAN is free, light weight, open source utility written in Bash.
Table of Contents
Install SDKMAN On Linux
Installing SDKMAN is trivial. First, make sure you have installed zip and unzip applications. It is available in the default repositories of most Linux distributions. For instance, to install unzip on Debian-based systems, simply run:
$ sudo apt-get install zip unzip
Then, install SDKMAN using command:
$ curl -s "https://get.sdkman.io" | bash
It's that simple. This command will install SDKMAN in $HOME/.sdkman location.
Sample output:
-+syyyyyyys: `/yho:` -yd. `/yh/` +m. .oho. hy .` .sh/` :N` `-/o` `+dyyo:. .yh:` `M- `-/osysoym :hs` `-+sys: hhyssssssssy+ .sh:` `N: ms/-`` yy.yh- -hy. `.N-````````+N. `od/` `N- -/oM- ddd+` `sd: hNNm -N: :do` .M. dMMM- `ms. /d+` `NMMs `do .yy- :N` ```mMMM. - -hy. /MMM: yh `+d+` `:/oo/` `-/osyh/ossssssdNMM` .sh: yMMN` /m. -dh- :ymNMMMMy `-/shmNm-`:N/-.`` `.sN /N- `NMMy .m/ `oNs` -hysosmMMMMydmNmds+-.:ohm : sd` :MMM/ yy .hN+ /d: -MMMmhs/-.` .MMMh .ss+- `yy` sMMN` :N. :mN/ `N/ `o/-` :MMMo +MMMN- .` `ds mMMh do /NN/ `N+....--:/+oooosooo+:sMMM: hMMMM: `my .m+ -MMM+ :N. /NMo -+ooooo+/:-....`...:+hNMN. `NMMMd` .MM/ -m: oMMN. hs -NMd` :mm -MMMm- .s/ -MMm. /m- mMMd -N. `mMM/ .- /MMh. -dMo -MMMy od. .MMMs..---yh +MMM. sNo`.sNMM+ :MMMM/ sh`+MMMNmNm+++- mMMM- /--ohmMMM+ :MMMMm. `hyymmmdddo MMMMh. ```` `-+yy/`yMMM/ :MMMMMy -sm:.``..-:-.` dMMMMmo-.``````..-:/osyhddddho. `+shdh+. hMMM: :MmMMMM/ ./yy/` `:sys+/+sh/ .dMMMMMMmdddddmmNMMMNNNNNMMMMMs sNdo- dMMM- `-/yd/MMMMm-:sy+. :hs- /N` `/ymNNNNNNNmmdys+/::----/dMMm: +m- mMMM+ohmo/.` sMMMMdo- .om: `sh `.-----+/.` `.-+hh/` `od. NMMNmds/ `mmy:` +mMy `:yy. /moyso+//+ossso:. .yy` `dy+:` .. :MMMN+---/oys: /+m: `.-:::-` /d+ +MMMMMMMNh:` +MN/ -yh. `+hddhy+. /MM+ .sh: :NMo -sh/ -NMs `/yy: .NMy `:sh+. `mMm` ./yds- `dMMMmyo:-.````.-:oymNy:` +NMMMMMMMMMMMMMMMMms:` -+shmNMMMNmdy+:` Now attempting installation... Looking for a previous installation of SDKMAN... Looking for unzip... Looking for zip... Looking for curl... Looking for sed... Installing SDKMAN scripts... Create distribution directories... Getting available candidates... Prime the config file... Download script archive... ######################################################################## 100.0% Extract script archive... Install scripts... Set version to 5.8.3+506 ... Attempt update of interactive bash profile on regular UNIX... Added sdkman init snippet to /home/ostechnix/.bashrc Attempt update of zsh profile... Updated existing /home/ostechnix/.zshrc All done! Please open a new terminal, or run the following in the existing one: source "/home/ostechnix/.sdkman/bin/sdkman-init.sh" Then issue the following command: sdk help Enjoy!!!
Once the installation is completed, run the following command to initialize SDKMAN:
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
If you want to install it in a custom location of your choice other than $HOME/.sdkman, for example /usr/local/, do:
$ export SDKMAN_DIR="/usr/local/sdkman" && curl -s "https://get.sdkman.io" | bash
Make sure your user has full access rights on this folder.
Finally, check if the installation is succeeded using command:
$ sdk version
Sample output:
==== BROADCAST ================================================================= * 2020-06-27: sbt 1.3.13 released on SDKMAN! #scala * 2020-06-26: Micronaut 2.0.0 released on SDKMAN! #micronautfw * 2020-06-22: Micronaut 2.0.0.RC2 released on SDKMAN! #micronautfw ================================================================================ SDKMAN 5.8.3+506
Congratulations! SDKMAN has been installed. Let us go ahead and see how to install and manage SDKs.
Manage Multiple Software Development Kits Using SDKMAN
List all available software development kits (SDK)
To view the list of all available candidates (SDKs), run:
$ sdk list
Sample output:
================================================================================ q-quit /-search down j-down ?-search up k-up h-help -------------------------------------------------------------------------------- Ant (1.10.1) https://ant.apache.org/ Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks. $ sdk install ant -------------------------------------------------------------------------------- AsciidoctorJ (2.3.1) http://asciidoctor.org/ AsciidoctorJ is the official library for running Asciidoctor on the JVM. Using AsciidoctorJ, you can convert AsciiDoc content or analyze the structure of a parsed AsciiDoc document from Java and other JVM languages. :
As you can see, SDKMAN list one candidate at a time along with the description of the candidate, official website and the installation command. Press ENTER key to list the next candidates. To close it, press q.
Install a new SDK
To install a SDK, for example Java JDK, run:
$ sdk install java
Sample output:
Downloading: java 11.0.7.hs-adpt In progress... ################################################################################################################################################################### 100.0%################################################################################################################################################################### 100.0% Repackaging Java 11.0.7.hs-adpt... Done repackaging... Installing: java 11.0.7.hs-adpt Done installing! Setting java 11.0.7.hs-adpt as default.
We have just installed Java. Let us check its version:
$ java --version openjdk 11.0.7 2020-04-14 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)
If there are multiple SDKs already present, it will prompt if you want the currently installed version to be set as default. Answering Yes will set the currently installed version as default.
Install specific version of SDK
To install particular version of a SDK, do:
$ sdk install ant 1.10.1
The above command will install Ant version 1.10.1.
If you already have local installation of a specific candidate, you can set it as local version like below.
$ sdk install groovy 3.0.0-SNAPSHOT /path/to/groovy-3.0.0-SNAPSHOT
List candidate versions
To list a particular candidates versions:
$ sdk list ant
Sample output:
================================================================================ Available Ant Versions ================================================================================ > * 1.10.1 1.10.0 1.9.9 1.9.8 1.9.7 ================================================================================ + - local version * - installed > - currently in use ================================================================================
As you see in the above output, the ant 1.10.1 is prefixed with ">" and "*". Here, > indicates that this version is currently in use and the * indicates that it is the default version.
Set default SDK
Like I already said, If you have installed multiple versions, SDKMAN will prompt whether you want the currently installed version to be set as default. You can answer Yes to set it as default. Also, you can do that later by using the following command:
$ sdk default ant 1.9.9
The above command will set Apache Ant version 1.9.9 as default.
Use specific SDK for current shell
You can choose a particular candidate version to use in the current shell.
$ sdk use ant 1.9.9
Please note that this will make the given version to use in the current session only. To make it permanent, use "default" command as shown above.
Display versions currently in use
To check what is currently in use for a Candidate, for example Java, run:
$ sdk current java Using java version 8.0.172-zulu
To check what is currently in use for all Candidates, for example Java, run:
$ sdk current Using: ant: 1.10.1 java: 8.0.172-zulu
Upgrade candidates
To upgrade an outdated candidate, do:
$ sdk upgrade scala
You can also check what is outdated for all candidates as well.
$ sdk upgrade
Offline mode
SDKMAN has offline mode feature that allows the SDKMAN to function when working offline. You can enable or disable the offline mode at any time by using the following commands:
$ sdk offline enable
$ sdk offline disable
Removing installed SDKs
To remove an installed SDK, run:
$ sdk uninstall ant 1.9.9
Getting help
To display help section, run:
$ sdk help Usage: sdk <command> [candidate] [version] sdk offline <enable|disable> commands: install or i <candidate> [version] uninstall or rm <candidate> <version> list or ls [candidate] use or u <candidate> [version] default or d <candidate> [version] current or c [candidate] upgrade or ug [candidate] version or v broadcast or b help or h 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
Update SDKMAN
The following command installs a new version of SDKMAN if available.
$ sdk selfupdate
SDKMAN will also periodically check for any updates and let you know with instruction on how to update.
WARNING: SDKMAN is out-of-date and requires an update. $ sdk update Adding new candidates(s): scala
Remove cache
It is recommended to clean the cache that contains the downloaded SDK binaries from time to time. To do so, simply run:
$ sdk flush archives
It is also good to clean temporary folder to save up some space:
$ sdk flush temp
Uninstall SDKMAN
If you don't need SDKMAN or don't like it, remove as shown below.
$ tar zcvf ~/sdkman-backup_$(date +%F-%kh%M).tar.gz -C ~/ .sdkman $ rm -rf ~/.sdkman
Finally, open your .bashrc (or .bash_profile or .profile) file:
$ nano ~/.bashrc
Find and remove the following lines.
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!! export SDKMAN_DIR="/home/ostechnix/.sdkman" [[ -s "/home/ostechnix/.sdkman/bin/sdkman-init.sh" ]] && source "/home/ostechnix/.sdkman/bin/sdkman-init.sh"
If you use ZSH, remove the above lines from the .zshrc file.
Related read:
- How To Manage Multiple Java Versions With jEnv On Linux
- How To Manage Multiple Python Versions With Pyenv On Linux
Resources:
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!
2 comments
You are encouraging users to be careless by piping downloaded scripts directly to bash.
No. I don’t. I have posted the official installation instructions.