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.
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
List all of the java versions available through sdkman
sdk list java
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
This command specifies the java version to use for the current shell.
sdk use java 19.0.2-zulu
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.
(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