Search code examples
javajava-home

Where is the Java SDK folder in my computer? Ubuntu 12.04


I know it's installed because when I type:

$java -version

I get:

OpenJDK Runtime Environment (IcedTea6 1.12.5) (6b27-1.12.5-0ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

And when I type:

$locate jdk

I get:

/home/arturo/Documents/2012a/sys/java/jre/glnxa64/jre/lib/servicetag/jdk_header.png
/usr/share/app-install/desktop/openjdk-6-jre:openjdk-6-java.desktop
/usr/share/app-install/desktop/openjdk-7-jre:openjdk-7-java.desktop
/usr/share/app-install/icons/openjdk-6.png
/usr/share/app-install/icons/openjdk-7.png

What worries me about the first item in the list is that the 2012a folder is my MATLAB folder and not a standard 'usr/lib' folder. I'm really confused on where the JDK and JRE got installed, because I need to set the $JAVA_HOME path pointing to the folder. Where am I missing something?


Solution

  • WAY-1 : Updated for the shortest and easy way

    Below command will give you the path, But it will only work if java command is working in other words if java path is configured.

    readlink -f $(which java) 
    

    Read more at Where can I find the Java SDK in Linux?


    WAY-2 (Better than WAY-1) : Below answer is still working and try it if above command is not working for you.

    You need to dig into symbolic links. Below is steps to get Java directory

    Step 1:

    $ whereis java
    java: /usr/bin/java /etc/java /usr/share/java
    

    That tells the command java resides in /usr/bin/java.

    Dig again:

    Step 2:

    $ ls -l /usr/bin/java
    lrwxrwxrwx 1 root root 22 2009-01-15 18:34 /usr/bin/java -> /etc/alternatives/java
    

    So, now we know that /usr/bin/java is actually a symbolic link to /etc/alternatives/java.

    Dig deeper using the same method above:

    Step 3:

    $ ls -l /etc/alternatives/java
    lrwxrwxrwx 1 root root 31 2009-01-15 18:34 /etc/alternatives/java -> /usr/local/jre1.6.0_07/bin/java
    

    So, thats the actual location of java: /usr/local/jre.....

    You could still dig deeper to find other symbolic links.


    Reference : where is java's home dir?