How to change JDK from command line in Windows?

[Last Updated: May 20, 2018]

Java Tools & Commands Java 

To use different JDK than the one which is on the default path. Use followings:

set path=<complete-path-of-new-jdk>;%path%

For example:

set path=C:\jdk1.8.0_151\bin;%path%


Default JDK on path:

D:>java -version
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)


D:>set path=C:\jdk1.8.0_151\bin;%path%

After change:

D:>java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

See Also