6

I get the following error while trying to compile or run everything that has to do with java or javac:

Error occurred during initialization of VM
java/lang/ClassNotFoundException: error in opening JAR file <Zip file open error> /usr/lib/jvm/java-8-oracle/jre/lib/rt.jar

I've read here that i should uninstall and install again JDK, here it is written that I should know which version of java I have installed on my pc in order to uninstall-it.

To check the version installed i run java -version but i get the error mentioned above, how can i check my java version without that command?

I know that i have installed java 8 but i don't know precisely which version it is.

David Foerster
  • 36,890
  • 56
  • 97
  • 151

4 Answers4

6

To show what version of Java is installed without running java -version, open the terminal and type:

apt policy openjdk-* oracle-java* 

A small part of the results of apt policy openjdk-* looks like this:

openjdk-7-jre-lib:
  Installed: (none)
  Candidate: (none)
  Version table:
openjdk-8-jdk:
  Installed: 8u162-b12-0ubuntu0.16.04.2
  Candidate: 8u162-b12-0ubuntu0.16.04.2

Search for sections that contain either openjdk-*-jre , openjdk-*-jdk or oracle-java* where the wildcard * character can be a Java version number like 6, 7, 8 or 9.

karel
  • 122,292
  • 133
  • 301
  • 332
5

You can discover the full path of the default java executable with:

readlink -f "$(which java)"

All (sane) Java packages or bundles that I know use installation path names that include the vendor name and major version number which would answer your question. E. g. on my system

$ readlink -f "$(which java)"
/usr/lib/jvm/java-9-openjdk-amd64/bin/java

tells me that the default Java installation is OpenJDK 9.

David Foerster
  • 36,890
  • 56
  • 97
  • 151
3

You could also try:

dpkg -l | egrep -i 'jre|java|jdk'
David Foerster
  • 36,890
  • 56
  • 97
  • 151
muclux
  • 5,324
2

You can use this command for checking your java version:

update-alternatives --config java
Campa
  • 1,022
Eranda Peiris
  • 761
  • 7
  • 17