Linux – “which” and “whereis”

linux

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?

Best Answer

  • From 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.

  • Related Question