Command Line shows only jdk 20 version of java, not others

165 views Asked by At

I want to see the list of all jdk versions available in my system. However, when I type in java and javac version to the cmd line, it gives me only jdk 20 version. How can I do an implementation to see other jdk versions as well in the list?

C:\Users\USER>java --version
java 20 2023-03-21
Java(TM) SE Runtime Environment (build 20+36-2344)
Java HotSpot(TM) 64-Bit Server VM (build 20+36-2344, mixed mode, sharing)

C:\Users\USER>javac --version
javac 20

C:\Users\USER>

I just typed java --version and javac --version commands to see jdk versions exist in my computer. Due to my assignment, I need jdk8 version. How can solve the problem in order to see the version I need?

1

There are 1 answers

0
Geoffrey On

You're going to have big headaches if you try to handle multiple java versions manually. The best option is to delegate this to a third party tool, quite some already exists to overcome the issue. The best one and recommended by several frameworks (https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started.installing.cli.sdkman) is sdkman:

https://sdkman.io/

Follow windows installation: https://sdkman.io/install#:~:text=Windows%20installation

Then do:

sdk list java

You will see something like:

================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier
--------------------------------------------------------------------------------
 Corretto      |     | 21           | amzn    |            | 21-amzn             
               |     | 21.0.1       | amzn    |            | 21.0.1-amzn         
               |     | 20.0.2       | amzn    |            | 20.0.2-amzn         
               |     | 20.0.1       | amzn    |            | 20.0.1-amzn         
               |     | 17.0.9       | amzn    |            | 17.0.9-amzn         
               |     | 17.0.8       | amzn    |            | 17.0.8-amzn         
               | >>> | 17.0.7       | amzn    | installed  | 17.0.7-amzn         
               |     | 11.0.21      | amzn    |            | 11.0.21-amzn        
               |     | 11.0.20      | amzn    |            | 11.0.20-amzn        
               |     | 11.0.19      | amzn    |            | 11.0.19-amzn        
               |     | 11.0.18      | amzn    | local only | 11.0.18-amzn        
               |     | 8.0.392      | amzn    |            | 8.0.392-amzn        
               |     | 8.0.382      | amzn    |            | 8.0.382-amzn        
               |     | 8.0.372      | amzn    | installed  | 8.0.372-amzn        

Install what you need with:

sdk install java 20.0.2-amzn

Then switch among versions with:

sdk use java 20.0.2-amzn