bashsdkshsdkman

How to use SDKMAN! to install packages from within scripts


Having SDKMAN! installed (http://sdkman.io/), I can install packages from the command line using for example:

sdk install java 8u144-zulu

However, when I try to do the same thing from within a script "my-installer.sh", I get error message: "sdk: command not found".

my-installer.sh:

#!/bin/bash
sdk install java 8u144-zulu

What am I doing wrong?


Solution

  • you need to source in ~/.sdkman/bin/sdkman-init.sh, like in

    #!/bin/bash
    . /home/alexw/.sdkman/bin/sdkman-init.sh
    sdk install java 8u144-zulu
    

    'sdk' is a bash function declared in sdkman-init.sh, and your first line (#!...) starts a new(!) shell.

    hope that helps! weHe