199

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?

Arturo
  • 3,679
  • 6
  • 34
  • 43
  • 4
    `java -version` doesn't tell you that you have a JDK installed. It tells you that you have a JRE installed. What does `javac -version` tell you? – Matt Ball Jun 05 '13 at 04:03
  • 1
    Can you see if http://stackoverflow.com/questions/9612941/how-to-set-java-environment-path-in-ubuntu helps? – midhunhk Jun 05 '13 at 04:04
  • javac -version gives me this: javac 1.6.0_27 – Arturo Jun 05 '13 at 04:20
  • "Can you see if stackoverflow.com/questions/9612941/… helps?" Unfortunately it doesn't when I type $locate jvm, I don't seem to have that folder even though I'm sure its installed. EDIT: Nevermind, I found it thanks! – Arturo Jun 05 '13 at 04:23

12 Answers12

425

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?

Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
159

Please use this command:

readlink -f $(which java)

It works for me with Ubuntu gnome.

On my computer the result is:

/usr/lib/jvm/java-7-oracle/jre/bin/java

Regards.

Ngoc Nguyen
  • 3,431
  • 1
  • 16
  • 7
35

In generally, java gets installed at /usr/lib/jvm . That is where my sun jdk is installed. check if it is same for open jdk also.

Pratap Singh
  • 4,607
  • 1
  • 22
  • 24
12
$whereis java
java: /usr/bin/java /usr/bin/X11/java /usr/share/java     /usr/share/man/man1/java.1.gz
$cd /usr/bin
$ls -l java
lrwxrwxrwx 1 root root 22 Apr 15  2014 java -> /etc/alternatives/java
$ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 39 Apr 15  2014 /etc/alternatives/java ->     /usr/lib/jvm/java-7-oracle/jre/bin/java

So,JDK's real location is /usr/lib/jvm/java-7-oracle/

Bom Wu
  • 131
  • 1
  • 3
7

Location of JRE in Ubuntu:

/usr/lib/jvm/java-7-oracle/jre

Dinesh Kumar P
  • 1,128
  • 2
  • 18
  • 32
6

$ whereis java

java: /usr/bin/java /usr/lib/java /usr/bin/X11/java /usr/share/java /usr/share/man/man1/java.1.gz

Pamador
  • 158
  • 2
  • 8
5

On Ubuntu 14.04, it is in /usr/lib/jvm/default-java.

thSoft
  • 21,755
  • 5
  • 88
  • 103
3

For me, on Ubuntu, the various versions of JDK were in /usr/lib/jvm.

Lewis
  • 4,285
  • 1
  • 23
  • 36
2

I found the solution to this with path name: /usr/lib/jvm/java-8-oracle

I'm on mint 18.1

ratsky
  • 41
  • 1
2

I am using Ubuntu 18.04.1 LTS. In my case I had to open the file:

/home/[username]/netbeans-8.2/etc/netbeans.conf

And change the jdk location to:

netbeans_jdkhome="/opt/jdk/jdk1.8.0_152"

Then saved the file and re-run Netbeans. It worked for me.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
0

you can simply write the following command in the terminal of your linux system and get the java path :- echo $JAVA_HOME

Yuvraj Singh
  • 137
  • 1
  • 4
0

The easiest way to do so is by typing echo $JAVA_HOME on your terminal.

Mostafa Wael
  • 2,750
  • 1
  • 21
  • 23