Skip to content

Instantly share code, notes, and snippets.

@kranthilakum
Last active December 2, 2022 20:03
Show Gist options
  • Save kranthilakum/7afb549b23eee5867653e0cd18e2c5f1 to your computer and use it in GitHub Desktop.
Save kranthilakum/7afb549b23eee5867653e0cd18e2c5f1 to your computer and use it in GitHub Desktop.
Use multiple Java versions with SDK manager

Install SDK Manager

$ curl -s "https://get.sdkman.io" | bash

List available Java versions

$ sdk list java

 Temurin       |     | 19           | tem     |            | 19-tem              
               |     | 19.0.1       | tem     |            | 19.0.1-tem          
               |     | 17.0.5       | tem     |            | 17.0.5-tem          
               |     | 17.0.4.1     | tem     |            | 17.0.4.1-tem        
               |     | 11.0.17      | tem     |            | 11.0.17-tem         
               |     | 11.0.16.1    | tem     |            | 11.0.16.1-tem       
               |     | 8.0.352      | tem     |            | 8.0.352-tem         
               |     | 8.0.345      | tem     |            | 8.0.345-tem  

Install Java 11 Temurin

$ sdk install java 11.0.17-tem  

Downloading: java 11.0.17-tem

In progress...

########################################################################################################################## 100.0%

Repackaging Java 11.0.17-tem...

Done repackaging...
Cleaning up residual files...

Installing: java 11.0.17-tem
Done installing!

Setting java 11.0.17-tem as default.

$ java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment Temurin-11.0.17+8 (build 11.0.17+8)
OpenJDK 64-Bit Server VM Temurin-11.0.17+8 (build 11.0.17+8, mixed mode)

Install Java 19 Temurin

$ sdk install java 19.0.1-tem

Downloading: java 19.0.1-tem

In progress...

########################################################################################################################## 100.0%

Repackaging Java 19.0.1-tem...

Done repackaging...
Cleaning up residual files...

Installing: java 19.0.1-tem
Done installing!

Do you want java 19.0.1-tem to be set as default? (Y/n): n

List available Java versions

 Temurin       |     | 19           | tem     |            | 19-tem              
               |     | 19.0.1       | tem     | installed  | 19.0.1-tem          
               |     | 17.0.5       | tem     |            | 17.0.5-tem          
               |     | 17.0.4.1     | tem     |            | 17.0.4.1-tem        
               | >>> | 11.0.17      | tem     | installed  | 11.0.17-tem         
               |     | 11.0.16.1    | tem     |            | 11.0.16.1-tem       
               |     | 8.0.352      | tem     |            | 8.0.352-tem         
               |     | 8.0.345      | tem     |            | 8.0.345-tem 

Check Java version

$sdk current java

Using java version 11.0.17-tem

Use Java v19

$ sdk use java 19.0.1-tem

Using java version 19.0.1-tem in this shell.

Set Java v11 as default

$ sdk default java 11.0.17-tem 

Default java version set to 11.0.17-tem

$ sdk current java

Using java version 19.0.1-tem

$ java -version

openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment Temurin-11.0.17+8 (build 11.0.17+8)
OpenJDK 64-Bit Server VM Temurin-11.0.17+8 (build 11.0.17+8, mixed mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment