boxofox's picture

This is a lesson learned I'd like to share.  tl;dr beware the bash hash.

While running a TurnKey Core guest, I decided to replace vim-tiny with the full version.

# apt-get remove vim-tiny
# apt-get install vim

Upon my next attempt to run vim, bash replied with an error:

# vim
bash: /usr/local/bin/vim: No such file or directory

Bash is still searching for vim-tiny's symbolic link at /usr/local/bin/vim, but I just uninstalled it.  The PATH environment variable is valid, and which sees vim.

# env | grep -i path
PATH=/usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# which vim
/usr/bin/vim

There is no bash alias for vim, so as a final effort to find some clue I ran:

# type vim
vim is hashed (/usr/local/bin/vim)

According to bash's man page:

Bash uses a hash table to remember the full pathnames of
executable files (see hash under SHELL BUILTIN COMMANDS
below).  A full search of the directories in PATH is
performed only if the command is not found in the hash table.

So because the bash hash remembered the vim-tiny symbolic link, I could not simply run vim from the command line anymore.  The fix is to tell bash hash to either forget about vim, or remember vim's new location.

# hash vim
# vim
success \o/

Hopefully this helps fellow newbs avoid spending too much time trying to figure this out

Forum: 
Jeremy Davis's picture

Is because most distros don't have vim-tiny installed by default? I don't know for sure, but I suspect that you would find the same behaviour in Debian (and maybe Ubuntu too even) if you installed vim-tiny, used it, uninstalled it and installed vim...

If that's so, then really it is a Debian bug?! Not really sure how you'd resolve it though... Perhaps the 'hash vim' command should be run as part of the installation of vim? Or maybe removing the hash (somehow?) as part of the removal of vim-tiny? TBH I'm not sure exactly...

[update] Out of interest I just double checked and it looks like by default Debian (and Ubuntu?) use vim-tiny, although 'vim' (full vim) is also installed... So not too sure about all that...

Add new comment