Manage Multiple JDKs on Mac OS, Linux and Windows WSL2

Courtesy of Karakun AG

The Manual Way

The Better Way

Install Multiple JDKs

$ sdk list java
$ sdk install java <id>
  1. AdoptOpenJDK build of OpenJDK 8u252 — LTS
  2. AdoptOpenJDK build of OpenJDK 11.0.7 — LTS
  3. Oracle OpenJDK 14 — Latest GA
  4. Oracle OpenJDK 15 — Early Access Builds of next release
$ cd /Users/bruno/.sdkman/candidates/java$ ls
11.0.7.hs-adpt 14.0.1-open 15.ea.20-open 8.0.252.hs-adpt
$ sdk current java
Using java version 15.ea.19-open
$ sdk default java 15.ea.20-open
Default java version set to 15.ea.20-open

Manage Multiple JDKs with jEnv

$ cd ~/.sdkman/candidates/java$ ls -1
11.0.7.hs-adpt
14.0.1-open
15.ea.20-open
8.0.252.hs-adpt
$ jenv add 15.ea.20-open
openjdk64-15-ea added
15-ea added
15-ea added
...$ jenv versions
system
1.8
1.8.0.252
11.0
11.0.7
14.0
14.0.1
* 15-ea (set by /Users/bruno/.jenv/version)
openjdk64-1.8.0.252
openjdk64-11.0.7
openjdk64-14.0.1
openjdk64-15-ea
  1. Set a Java version for your overall system.
  2. Set a Java version for the current directory/project you are in.
  3. Set a Java version for the current shell.

Auto-Switch Between Multiple JDKs

$ jenv global 15
$ jenv local 1.8
$ cat .java-version
───────┬────────────────────────────────────────────────────────────
│ File: .java-version
───────┼────────────────────────────────────────────────────────────
1 │ 11.0
───────┴────────────────────────────────────────────────────────────

** Update May 2020

sss dsadas
  • SDKMAN! now supports sdk env, with auto-switch now available since May 4th in version 5.8.1+.
  • direnv is very nice as it is agnostic but covers exactly what jEnv is designed for, except it doesn't help you with the ease of switching between JDKs. You have to edit files manually.
  • autoenv is just another alternative to direnv with the same limitations.
  • jabba is the most promising alternative to a combo SDKMAN+jEnv as it supports all use cases and also works on Windows (PowerShell), something that none of the options above support.

Brazilian, Product and Program Manager for Java at Microsoft. Promoting great developer technologies to the world. Previously at Oracle.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

FTP and remote ssh automation using shell script

Query S3 data via Hive on local box

Sharing common developer frustrations and how to overcome them, plus updates from Apple, Android…

How to create your first API documentation and build the website that displays the current foreign…

Journey into Code

19 tips for Gradle in Android projects - 2019 Edition

แนะนำ VMware Site Recovery Manager และ VMware vSphere Replication

CC:Pen testing Section 1 Walkthrough [TryHackme]

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bruno Borges

Bruno Borges

Brazilian, Product and Program Manager for Java at Microsoft. Promoting great developer technologies to the world. Previously at Oracle.

More from Medium

Setting up self-signed SSL certificates for local development in WSL2

I Created My Own Wordle Using Azure Functions, Azure Cosmos DB, and Flutter

Doing away with passwords in ASP.NET

[Video] Polymorphic JSON Serialization (feat. .NET & System.Text.Json)