Skip to content

Instantly share code, notes, and snippets.

@tfield
Last active December 23, 2024 03:33
Show Gist options
  • Save tfield/55064fc0c3f80fa67f624874f0b8d55e to your computer and use it in GitHub Desktop.
Save tfield/55064fc0c3f80fa67f624874f0b8d55e to your computer and use it in GitHub Desktop.
SDKMAN vs JENV

sdkman vs jenv

Jenv is great, but the JDKs have to be manually installed. If you need more than just a couple of them, you'll want to be able to install them via command line, and sdkman provides this capability very cleanly for java. So... is it possible to work with both sdkman and jenv? Yes and no. Some tricks will allow you to tell jenv about the java versions that are managed by sdkman, but setting defaults (using jenv local 17.0 for instance) does not work very well. Time for a cleaner solution. Sdkman provides all of the same functionality, with more power and a slightly different (but equally simple) syntax. I've switched from jenv to sdkman. Here's my cheat sheet.

Setup

Download and install sdkman. Follow the required instructions after installing. Then, run the config command to enable auto_env support.

echo “Installing SDKMAN"
curl -s https://get.sdkman.io | bash
echo 'Configuring auto-env: change the value of sdkman_auto_env from false to true'
echo 'Press any key to continue...'; read -k1 -s
sdk config

To list available java versions

List all of the java versions available through sdkman

sdk list java

To install some java versions

Install whatever java versions you intend to use on your system. Here are some examples

sdk install java 20-zulu 
sdk install java 19.0.2-zulu   
sdk install java 17.0.7-zulu 
sdk install java 11.0.19-zulu  
sdk install java 8.0.372-zulu  
sdk install java 22.3.1.r19-grl

To use a specific version

This command specifies the java version to use for the current shell.

sdk use java 19.0.2-zulu

To always use the specific version in a particular directory

Enter your project directory (every subfolder below it will pick up the parent directory's settings). Set your version then call env init, which creates a .sdkmanrc with the required SDKs in that folder. Note, you can add any required SDK here, it does not have to be just a java version. Need maven? Gradle? Groovy? Add them here too.

sdk use java java 17.0.7-zulu
sdk env init

Edit the .sdkmanrc file to add in additional dependencies as required.

To ensure that a project's SDKs are present

(requires the project to have a .sdkmanrc file in its root directory)

This is great when downloading a new project from git, onboarding other team members, etc. This will ensure that all of the required SDKs are installed and available.

sdk env install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment