Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

which -a ruby gives me

/usr/ruby
/usr/ruby
/usr/ruby

It gives the same path three times. Why does this happen?

share|improve this question
2  
A hint: pastebin.com/8HNbDvnD. Some solutions: keep duplicates out of $PATH on source –  manatwork Mar 6 '13 at 13:36
add comment

4 Answers

up vote 9 down vote accepted

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.

share|improve this answer
2  
To expand: The -a option reports ALL matches in your PATH. That's what it's for. If, as noted, your $PATH references the same place more than once, or the same executable is in more than one place, it'll show up multiple times with -a (but not when omitting that option). –  SuperMagic Mar 6 '13 at 14:55
add comment

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.

share|improve this answer
add comment

Take a look at your path:

echo $PATH

There are duplicate entries in your path (or ruby is installed several times in different locations).

share|improve this answer
add comment

Try

whereis -b ruby

If you are getting the same output, then the problem is in your PATH.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.