Skip to content

Instantly share code, notes, and snippets.

@HariSekhon
Created October 13, 2024 01:44
Show Gist options
  • Save HariSekhon/8bc955cf194f1a1498c793ef3190b94f to your computer and use it in GitHub Desktop.
Save HariSekhon/8bc955cf194f1a1498c793ef3190b94f to your computer and use it in GitHub Desktop.
sdkman.md from HariSekhon/Knowledge-Base repo: https://github.com/HariSekhon/Knowledge-Base

SDKman

SDK Manager installs and manages multiple versions od JDKs .

Originally it was just for JDK languages and their main build systems, but has in recent years extended to a wider list of support technologies:

  • JDK languages - Java, Groovy, Scala, Kotlin
  • JDK related build systems - Maven, Gradle, SBT, Ant
  • JDK based frameworks - Grails, Spring Boot, JBang
  • JDK based products - Hadoop, Spark, Flink, ActiveMQ, Tomcat, JMeter, VisualVM etc.

Install SDKman

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

Add SDKman to $PATH:

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

Will usually add something like this to the end of your $HOME/.bash_profile login profile script:

#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="/Users/hari/.sdkman"
[[ -s "/Users/hari/.sdkman/bin/sdkman-init.sh" ]] && source "/Users/hari/.sdkman/bin/sdkman-init.sh"

How It Works Under the Hood

Future shells will then automatically call /Users/hari/.sdkman/bin/sdkman-init.sh to add paths like this:

/Users/hari/.sdkman/candidates/scala/current/bin
/Users/hari/.sdkman/candidates/sbt/current/bin
/Users/hari/.sdkman/candidates/maven/current/bin
/Users/hari/.sdkman/candidates/java/current/bin
/Users/hari/.sdkman/candidates/groovy/current/bin
/Users/hari/.sdkman/candidates/gradle/current/bin

early in your $PATH list to default to using whatever version of each SDK SDKman has installed and switched to internally via symlinks in each case to:

/Users/hari/.sdkman/candidates/<name>/<version>

and are atomically switched to different versions by the sdk use command.

Using SDKman

Help

Show list of commands:

sdk help

Update list of SDKs available to install:

sdk update

List all products SDKman can install

sdk list

(or sdk ls)

List Java versions

sdk list java

Install the latest Java SDK

sdk install java

(can also shorten to sdk i java)

Install another SDK version

sdk install java <version>

Switch to use another SDK Version

sdk use java <version>

List all the selected SDKs

sdk current

(or sdk c)

Output:

Using:

gradle: 7.3.3
groovy: 4.0.0
java: 21.0.4-tem
jbang: 0.119.0
maven: 3.8.4
pomchecker: 1.13.0
sbt: 1.6.2
scala: 3.1.1
visualvm: 2.1.10

List the Version of a Specific SDK

sdk current java

Output:

Using java version 21.0.4-tem

Delete a version of Java JDK installed

sdk rm java 21.0.4-tem
Deselecting java 21.0.4-tem...

Uninstalling java 21.0.4-tem...

Clean up temp space

sdk flush

Output:

       9 archive(s) flushed, freeing 619M       /Users/hari/.sdkman/archives.
      20 archive(s) flushed, freeing 104K       /Users/hari/.sdkman/tmp.
       9 archive(s) flushed, freeing  48K       /Users/hari/.sdkman/var/metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment