223

I installed JDK using apt-get install but I don't know where my jdk folder is. I need to set the path for that. Does any one have a clue on the location?

Ojasvi Monga
  • 4,437
  • 2
  • 18
  • 35
dinesh707
  • 12,106
  • 22
  • 84
  • 134

14 Answers14

450

This depends a bit from your package system ... if the java command works, you can type readlink -f $(which java) to find the location of the java command. On the OpenSUSE system I'm on now it returns /usr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/bin/java (but this is not a system which uses apt-get).


On Ubuntu, it looks like it is in /usr/lib/jvm/java-6-openjdk/ for OpenJDK, and in some other subdirectory of /usr/lib/jvm/ for Suns JDK (and other implementations as well, I think).

Debian is the same.


For any given package you can determine what files it installs and where it installs them by querying dpkg. For example for the package 'openjdk-6-jdk': dpkg -L openjdk-6-jdk

dsh
  • 12,037
  • 3
  • 33
  • 51
Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
  • 1
    orth looking in /usr/java too on some setups I've seen – jlb83 Nov 12 '14 at 14:52
  • If you are to add the JDK path in android studio, add this /usr/lib/jvm/java-8-oracle/ – Rohit Rokde Apr 05 '16 at 10:39
  • 5
    It seems my path is `/usr/lib/jvm/java-7-openjdk-amd64`. – einverne May 01 '16 at 08:04
  • 4
    I think readlink as given is most elegant (and efficient), but I suggest `readlink -f $(which javac)` - note the 'c' in case there is a strange mix of JDK and JRE on the same machine. The JDK includes a compiler (javac) and a JRE does not. However if path is not correct, which will fail and you can try this: `find /usr/java -wholename '*ava/jdk*' -prune` as I note in a comment below. – Steven the Easily Amused Sep 30 '16 at 23:11
  • @Winnemucca It works for me, you can find where java is and then you can find where jdk path. – einverne Jun 05 '17 at 10:20
  • in zoo.cfg file makesure you add the field `initLimit=10` or `initLimit=20` , this will help in first place when you gonna start zookeper for first time – Manoj Kalluri Nov 25 '17 at 18:33
  • On Debian/Ubuntu if you have the `default-jdk` or `default-jre` packages installed, you can resolve the symbolic link `/usr/lib/jvm/default-java` that will point to the default version installed JDK or JRE according with your OS version: `readlink -f /usr/lib/jvm/default-java` – Eduardo Apr 06 '22 at 15:17
56
update-java-alternatives -l

will tell you which java implementation is the default for your system and where in the filesystem it is installed. Check the manual for more options.

forcefsck
  • 2,725
  • 1
  • 17
  • 12
  • 8
    This is debian specific (at least). Other distros may not have this – dequis Oct 21 '14 at 02:26
  • 3
    @dequis, it's an answer specific to debian, since the question mentioned `apt-get` and the distro to be `Debian 2.6.26`. AFAIK, it should be the same for all debian derivatives. – forcefsck Oct 21 '14 at 12:09
  • 3
    I'm just pointing it out for other people. I know it's valid for this particular question. – dequis Oct 22 '14 at 06:34
  • 2
    update-alternatives --list | grep java worked for me on RHEL – Upen Feb 19 '19 at 06:41
32
$ which java 

should give you something like

/usr/bin/java
The Surrican
  • 29,118
  • 24
  • 122
  • 168
  • 2
    true. i bet it is after apt-get install – The Surrican Mar 09 '11 at 19:54
  • 9
    This does not actually point to a full JDK. 1. It is a symlink, and even if you read the symlink, the binary is also not within a JDK. For example, if I run the command `readlink -f $(which javac)` it prints `/usr/lib/jvm/java-8-oracle/bin/javac`. That bin folder is NOT a JDK. General acid-base test to see if its a JDK is to see if the current `$JAVA_HOME` contains a path of `lib/tools.jar` . In the cast of `/usr/lib/jvm/java-8-oracle/bin` that is not true, therefore it is not a JDK. – Zombies Jan 19 '16 at 07:37
  • On Centos / RHL This is what I prefer to find the JDK (if installed) `find /usr/java -wholename '*ava/jdk*' -prune` But behavior depends whether you are talking about OpenJDK or Oracle Java and how it was installed in the first place. – Steven the Easily Amused Sep 30 '16 at 23:04
13

This question will get moved but you can do the following

which javac

or

cd /
find . -name 'javac'
Andrew T Finnell
  • 13,417
  • 3
  • 33
  • 49
12

Use find to located it. It should be under /usr somewhere:

find /usr -name java

When running the command, if there are too many "Permission denied" message obfuscating the actual found results then, simply redirect stderr to /dev/null

find /usr -name java 2> /dev/null
Brent Worden
  • 10,624
  • 7
  • 52
  • 57
8

Another best way to find Java folder path is to use alternatives command in Fedora Linux (I know its for Ubuntu but I hit this post from google just by its headline). Just want to share incase people like me looking for answers for fedora flavour.

To display all information regarding java

alternatives --display java
Ankit Singh
  • 2,602
  • 6
  • 32
  • 44
5

Three Step Process: First: open Terminal->$ whereis java it would give output like this: java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz

Second: ls -l /usr/bin/java It would give output like this: lrwxrwxrwx 1 root root 22 Feb 9 10:59 /usr/bin/java -> /etc/alternatives/java

Third: ls -l /etc/alternatives/java output is the JDK path: lrwxrwxrwx 1 root root 46 Feb 9 10:59 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

Anubhav Gupta
  • 560
  • 6
  • 11
3

Simple, try it:

It's /usr/local/java/jdk[version]

Manos Nikolaidis
  • 21,608
  • 12
  • 74
  • 82
Ashansu Pant
  • 49
  • 1
  • 1
  • 3
3

This question still seems relevant, and the answer seems to be a moving target.

On my debian system (buster):

> update-java-alternatives -l
java-1.11.0-openjdk-amd64      1111       /usr/lib/jvm/java-1.11.0-openjdk-amd64

However, if you actually go look there, you'll see there are multiple directories and symbolic links placed there by the package system to simplify future maintenance.

The actual directory is java-11-openjdk-amd64, with another symlink of default-java. There is also an openjdk-11 directory, but it appears to only contain a source.zip file.

Given this, for Debian ONLY, I would guess the best value to use is /usr/lib/jvm/default-java, as this should always be valid, even if you decide to install a totally different version of java, or even switch vendors.

The normal reason to want to know the path is because some application wants it, and you probably don't want that app to break because you did an upgrade that changed version numbers.

2

the command: sudo update-alternatives --config java will find the complete path of all installed Java versions

Hasan
  • 296
  • 1
  • 8
  • 23
2

On Linux Fedora30 several versions of the full java JDK are available, specifically package names:

java-1.8.0-openjdk-devel.x86_64 
java-11-openjdk-devel.x86_64

Once installed, they are found in: /usr/lib/jvm

To select the location/directory of a full development JDK (which is different from the simpler runtime only JRE) look for entries:

ls -ld java*openjdk*

Here are two good choices, which are links to specific versions, where you will have to select the version:

/usr/lib/jvm/java-1.8.0-openjdk
/usr/lib/jvm/java-11-openjdk
Grant Rostig
  • 473
  • 1
  • 4
  • 13
1

below command worked in my debain 10 box!

root@debian:/home/arun# readlink -f $(which java)
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
Arun
  • 1,651
  • 4
  • 20
  • 31
0

on OpenSUSE 13.1/13.2 its: /usr/lib64/jvm/java-1.6.0-openjdk-(version-number)
version-number can be 1.7.x 1.8.x etc. check software manager witch version you have installed...

André

Dutch Glory
  • 23,373
  • 1
  • 17
  • 6
0

This is the best way which worked for me Execute this Command:-

$(dirname $(readlink $(which javac)))/java_home
Buddy
  • 10,874
  • 5
  • 41
  • 58