View the list of Java version installed and select the default

We can view the current java version installed in our system with:

java -version

My java version:

java version "1.7.0_141"
OpenJDK Runtime Environment (rhel- u141-b02)
OpenJDK 64-Bit Server VM (build 24.141-b02, mixed mode)

Viewing the list of Java version installed and selecting the default one

sudo update-alternatives --config java

This command will give you the list of installed Java versions.

My output was:

There are 2 programs which provide 'java'.

  Selection    Command
*+ 1           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-
   2           /usr/java/jdk1.8.0_131/jre/bin/java

1 is the selected currently in use, to make use of 2 typing 2 and pressing enter will choose jdk1.8.0_131 for me.

Now, if I do

java -version

The output is:

java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

About the Author

lakshman basnet portrait photo

Lakshman enjoys living with technology. Digital marketer by profession, he loves writing and sharing his experience about technology, life and travel in this blog.

Leave a comment