Multiple JDK is not working properly in Ubuntu 14.04

There is too much reasons why you can see this error.

Could you please run all this commands one by one, and post output here:

  1. file /usr/bin/java
  2. type /usr/bin/java
  3. echo $JAVA_HOME
  4. echo $PATH
  5. ls -ahl /usr/lib/jvm

Then - using update-alternatives choose jdk1.7.0_55 and run this

$ ldd $(which java)

using update-alternatives choose jdk1.7.0_21 and run this

$ ldd $(which java)

then again for jdk1.7.0_21 run this

$ sudo java -version

UPDATE. Answer

For everyone who has same problem:

First of all, run sudo ldconfig. It is safe to run ldconfig at any time

After a long discussion we concluded that jdk1.7.0_21 is corrupted.

How we determine it:

  1. When choose java jdk1.7.0_21, sudo java -version give error even if run as root.
  2. find /usr/lib/jvm -name "libjli.so", this command must show that libjli is located in folder where jdk1.7.0_21 installed. In our case it was not.

In other cases:

Check that jdk belongs to root:root

Check that /usr/bin/java is a symlink, not executable.

Check PATH, java should not be in the PATH, if you are using update-alternatives.

Also here is helpful links:

https://unix.stackexchange.com/questions/16656/problem-to-launch-java-at-debian-error-while-loading-shared-libraries-libjli

https://www.centos.org/forums/viewtopic.php?t=16398

https://superuser.com/questions/310371/problem-launch-java-on-debian-error-while-loading-shared-libraries-libjli-so