Switching between JDK 8 and 11 using SDKMAN

Posted at — Sep 26, 2018

I have written about switching JDK versions on your mac before. With JDK 11 now being out, it is time to give an updated version.

You can make switching between the Oracle JDK 8 and the OpenJDK 11 very easy if you use SDKMAN!. Just follow the installation instructions at https://sdkman.io/install to get started.

After that, run sdk list java. This will show something like this:

================================================================================

Available Java Versions

================================================================================

12.ea.12-open

11.0.0-open

10.0.2-zulu

10.0.2-open

10.0.2-oracle

9.0.7-zulu

9.0.4-open

8.0.181-zulu

8.0.181-oracle

7.0.181-zulu

1.0.0-rc6-graal

================================================================================

+ - local version

* - installed

> - currently in use

================================================================================

We can now install Oracle JDK 8 with: sdk install java 8.0.181-oracle

And OpenJDK 11 after that with: sdk install java 11.0.0-open

During the installation, you can choose what version to make the default.

If you run sdk list java again, you will see what versions are installed and what version is the default one:

================================================================================

Available Java Versions

================================================================================

12.ea.12-open

* 11.0.0-open

10.0.2-zulu

10.0.2-open

10.0.2-oracle

9.0.7-zulu

9.0.4-open

8.0.181-zulu

> * 8.0.181-oracle

7.0.181-zulu

1.0.0-rc6-graal

================================================================================

+ - local version

* - installed

> - currently in use

================================================================================

To temporarily switch to another version, use the sdk use command. For instance, if you made JDK 8 the default, then switch to JDK 11 in the current session by typing:

sdk use java 11.0.0-open

Result:

21:08 $ java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

To set a permanent default, use the sdk default command. For instance, to make JDK 11 the default, type:

sdk default java 11.0.0-open
If you want to be notified in the future about new articles, as well as other interesting things I'm working on, join my mailing list!
I send emails quite infrequently, and will never share your email address with anyone else.