How to find which version of Java in Java installed folder?

67,013

Solution 1

I think you can track all this by checking to where your java binaries linked to.

       #which javac
          /usr/bin/javac   
       #ls -ln /usr/bin/java
           lrwxrwxrwx. 1 0 0 22 Nov 27 04:54 /usr/bin/java -> /etc/alternatives/java
       #ls -ln /usr/bin/javac
            lrwxrwxrwx. 1 0 0 23 Nov 27 04:54 /usr/bin/javac -> /etc/alternatives/javac
       # ls -ln /usr/bin/javadoc
            lrwxrwxrwx. 1 0 0 25 Nov 27 04:54 /usr/bin/javadoc -> /etc/alternatives/javadoc

and finally:

#ls -ld /etc/alternatives/java
lrwxrwxrwx. 1 root root 46 Nov 27 04:54 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java

therefore , my java installation is:

   /usr/lib/jvm/jre-1.7.0-openjdk.x86_64

I suppose you can track any binary like this.

Solution 2

Finding out which binary is executed when you type only the name is done using which, and using readlink you can condense the process to a single line.

readlink -e $(which java)

readlink -e prints the value of a symbolic link or canonical file name, and the -e ensures it follows every component recursively.

tony@trinity:~$ readlink -e $(which java)
/usr/lib/jvm/java-6-openjdk-i386/jre/bin/java

note: I don't have javac installed on the machine I tested this on, so just used java, but the above will work work for any binary.

You also appear to be asking to find out which version of java is in a specific folder? For that you just do this,

/full/path/java -version

which prevents Linux from search the path and finding the java binary directly. In your case,

/usr/lib/jvm/java-7-oracle/javac -version

Solution 3

On Debian and its derivatives You could use:

update-alternatives --config java

Or

update-alternatives --list java

With --config option you can set required java from list of alternatives.

Share:
67,013

Related videos on Youtube

Mr ASquare
Author by

Mr ASquare

Updated on September 18, 2022

Comments

  • Mr ASquare
    Mr ASquare over 1 year

    A version of java is installed on my Linux machine. When i try this:

    root@test$: javac -version

    It given the result as:

    javac jdk1.7.0_80.

    Now my problem is i don't know where that(1.7.0_80) java folder is. I have a folder named "java-7-oracle" in usr/lib/jvm. I am suspecting that it would be the folder for the installed version of java.

    Now I have a java folder and I want to know which version of java it is?

    How??