Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On my linux box, after typing which java, I get

/usr/bin/java

After typing whereis java, I get

java: /usr/bin/java /etc/java /usr/share/java /usr/share/man/man1/java.1.gz

What are the meanings of these two results? When setting up the JAVA_HOME, which one should I use?

share|improve this question

migrated from stackoverflow.com Jun 27 '11 at 3:15

This question came from our site for professional and enthusiast programmers.

    
What is your JAVA_HOME currently set to? –  andyb Jun 26 '11 at 23:04

5 Answers 5

From http://superuser.com/questions/40301/which-whereis-differences

which   (1) - shows the full path of (shell) commands
whereis (1) - locate the binary, source, and manual page files for a command

I'd use which as it shows you where just the binary is as I assume that is all you need. However Java could be installed somewhere else and which would not report it as it only searches for an executable or script in the directories listed in the environment variable PATH.

share|improve this answer
    
Note that whereis on Linux always uses a hard-coded list of directories, while which uses the PATH environment variable. –  grawity Jun 27 '11 at 11:20

which <executable> returns the first found executable on you PATH. In other words, what would be executed if <executable> were entered as a command.

share|improve this answer

JAVA_HOME should be a parent folder which contains the JDK or JRE, or in other words, it has /lib, /bin etc. folders from the Java distribution which contain libraries/dependencies for Java Runtime as well as executables. In your case it appears that /usr/share/java would be the best fit - check to see if it has subfolders from the distribution in there.

which command returns the first executable match, while whereis locates the other matches along with executable.

share|improve this answer

Here is an exerpt from man whereis :

  whereis  -  locate the binary, source, and manual page files for a command

So the second line you get contains both the binary location but also resources used by this app like the man page location, and sources...

If you want to set your PATH, it should point to /usr/bin/

If you want to set JAVA_HOME in order to get a real environment development in linux, I suggest you manually maintain your java jdk.

At home, I install java's jdk in /usr/local/java/jdk1.6...

and I make a symlink in /usr/local/java/jdk that points to the desired jdk.

My JAVA_HOME variable always point to /usr/local/java/jdk

Distros don't do a satisfying job to build a really good java environment for devs to my mind.

Regards, Stéphane

share|improve this answer

None of those.

JAVA_HOME should point to the root folder of your JDK

on my system:

$ echo $JAVA_HOME 
/etc/java-config-2/current-system-vm

$ ll /etc/java-config-2/current-system-vm 
lrwxrwxrwx 1 root root 24 mai   16  2009 /etc/java-config-2/current-system-vm -> /usr/lib/jvm/sun-jdk-1.6
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.