which -a ruby
gives me
/usr/ruby
/usr/ruby
/usr/ruby
It gives the same path three times. Why does this happen?
which -a ruby
gives me
/usr/ruby
/usr/ruby
/usr/ruby
It gives the same path three times. Why does this happen?
Check your path. It's not that hard to end up with duplicates in it. Example:
»echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:
»which -a bash
/bin/bash
/usr/bin/bash
This is because my /bin is a symlink to /usr/bin. Now:
»export PATH=$PATH:/usr/bin
»echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/bin
»which -a bash
/bin/bash
/usr/bin/bash
/usr/bin/bash
Since /usr/bin is now in my $PATH twice, which -a
finds the same bash twice.
As the hint says, and quoting from the manual page, "Which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument
had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same
algorithm as bash(1)."
As for the -a
option, it lists all the executables by that name found in $PATH.
Take a look at your path:
echo $PATH
There are duplicate entries in your path (or ruby is installed several times in different locations).
Try
whereis -b ruby
If you are getting the same output, then the problem is in your PATH.