I am using Ubuntu 14.04

i compiled vim and installed in /usr/local/bin

i uninstalled the earlier versions of vim installed.

why is bash looking for vim in /usr/bin ?

vimal@Tardis:~/VIM/vim$ which -a vim
vimal@Tardis:~/VIM/vim$ vim
bash: /usr/bin/vim: No such file or directory

vimal@Tardis:~/VIM/vim$ ls -al /usr/local/bin/
total 3216
drwxr-xr-x  2 root root    4096 Aug 10 11:39 .
drwxr-xr-x 11 root root    4096 Aug  9 11:51 ..
-rwxr-xr-x  1 root root  972502 Aug  9 12:33 ctags
lrwxrwxrwx  1 root root       3 Aug  9 22:24 ex -> vim
lrwxrwxrwx  1 root root       3 Aug  9 22:24 rview -> vim
lrwxrwxrwx  1 root root       3 Aug  9 22:24 rvim -> vim
lrwxrwxrwx  1 root root       3 Aug  9 22:24 view -> vim
-rwxr-xr-x  1 root root 2284512 Aug 10 11:39 vim
lrwxrwxrwx  1 root root       3 Aug  9 22:24 vimdiff -> vim
-rwxr-xr-x  1 root root    2084 Aug 10 11:39 vimtutor
-rwxr-xr-x  1 root root   18896 Aug 10 11:39 xxd
vimal@Tardis:~/VIM/vim$ id
uid=1001(vimal) gid=1001(vimal) groups=1001(vimal),4(adm),27(sudo),108(lpadmin),124(sambashare)
vimal@Tardis:~/VIM/vim$ echo $PATH 
  • 2
    Run hash -r and then try again. – John1024 Aug 10 '16 at 6:24
  • Show output of echo $PATH. In general, you just need to move in the variable the /usr/local/bin to be earlier than /usr/bin. But I'm asking the output because in my $PATH it is like this. But I can assume, though, that I swapped the order at some point of time, and just don't remember. – Hi-Angel Aug 10 '16 at 6:52
  • added echo $PATH output – weima Aug 10 '16 at 6:54
  • 2
    Why did you compile vim? Why not install it a normal way? – Pilot6 Aug 10 '16 at 6:55
  • \vim also returns the same result? – techraf Aug 10 '16 at 7:24

Quoting the bash manual:

Bash uses a hash table to remember the full pathnames of executable files. A full search of the directories in PATH is performed only if the command is not found in the hash table.

Here, what happened is that you:

  1. removed the original /usr/bin/vim, and
  2. created a new /usr/local/bin/vim.

In this case, bash's path hash table was never updated, so when you call vim after 1 and 2, it finds the old hashed path. To force a path hash update, use hash -r.

AFAICT, bash has a strange and undocumented behavior, in that:

If you call vim between 1 and 2 (leading to a legitimate "command not found"), then the hashed path is automatically removed, so when you call vim again after 2, it works just fine.

What I don't understand is why bash doesn't automatically remove the path when vim is called after 1 and 2 (as in your case), and the wrong path is found. But that's what's happening.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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