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.

I look to see where the command is located:

xxx:~/mono/mono-2.6.7$ which mono
/usr/local/bin/mono

If I execute it directly, no problem:

xxx:~/mono/mono-2.6.7$ /usr/local/bin/mono -V
Mono JIT compiler version 2.6.7 (tarball Mon Aug  2 16:01:50 UTC 2010)
Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com
....

But if I execute the command without the path it cannot find it:

xxx:~/mono/mono-2.6.7$ mono
bash: /usr/bin/mono: No such file or directory

There is no mono file in /usr/bin:

xxx:~/mono/mono-2.6.7$ ls -l /usr/bin/mono
ls: cannot access /usr/bin/mono: No such file or directory

Here is my path:

xxx:~/mono/mono-2.6.7$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Doesn't it search each directory separated by the colons? So shouldn't it find mono in /usr/local/bin ?

If I log in as root, it works. I can execute mono on the command line and it finds it. The permissions are:

xxx:~/mono/mono-2.6.7$ ls -l /usr/local/bin/mono
-rwxr-xr-x 1 root root 8452592 2010-08-02 16:23 /usr/local/bin/mono

Is the user I am using not part of the right group?

share|improve this question

migrated from serverfault.com Aug 3 '10 at 0:16

This question came from our site for professional system and network administrators.

3 Answers 3

Bash keeps a cache of command locations in memory, so that it doesn't have to do the whole PATH exploration each time you start a command. In your original bash session, bash had previously memorized that mono was /usr/bin/mono. Then you removed /usr/bin/mono and added /usr/local/bin/mono, but your running bash still had the old location in its cache.

You can manipulate the command location cache with the hash builtin. In particular hash -r clears the cache.

which is an external command, so it doesn't use bash's cache and performs a PATH lookup every time. You could also have used type, which is a builtin and therefore does use the lookup cache.

share|improve this answer
    
hash -r worked for me. Good answer! –  Florestan06 Sep 1 at 14:24

Maybe you have an alias defined for mono? Check out that the following files in your home directory: .bashrc, .profile, .login or *.bash_profile*

... does not contain something like this

 alias mono="/usr/bin/mono"

This can also be located in /etc/bashrc or /etc/profile.

Command alias shows all currently defined aliases.

share|improve this answer
    
Nope. No alias for mono. –  CShipley Aug 2 '10 at 16:51

I logged out, and then logged in again and it worked. I must have been doing something stupid. But, it works!

share|improve this answer
    
OK, great to hear that :) –  Janne Pikkarainen Aug 2 '10 at 17:05

Your Answer

 
discard

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