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.

  • "I know that i have installed java 8 but i don't know precisely which version it is." Installed how? – muru Apr 13 '18 at 12:14

You can use this command for checking your java version:

update-alternatives --config java
| improve this answer | |
  • 7
    Wouldn't update-alternatives --display java be simpler and better since OP only wants to “display” available Java versions, not change the default? That wouldn't even require sudo. – David Foerster Apr 13 '18 at 10:47

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:

  Installed: (none)
  Candidate: (none)
  Version table:
  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.

| improve this answer | |
  • thanks, with that command i got tons of lines which one should i search for? – Zeno Raiser Apr 13 '18 at 8:57

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)"

tells me that the default Java installation is OpenJDK 9.

| improve this answer | |

You could also try:

dpkg -l | egrep -i 'jre|java|jdk'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.