Ubuntu – /usr/local/bin first in PATH, but executable in /usr/bin found first

cmakepaths

I'm having a strange problem with an Ubuntu 12.04 server:

hithwen@ip:~$ cmake --version
cmake version 2.8.12.2

buildbot@ip:~$ cmake --version
cmake version 2.8.7

So, different users are executing different versions, ok, let's see where are they located:

hithwen@ip:~$ which cmake
/usr/local/bin/cmake

buildbot@ip:~$ which cmake
/usr/bin/cmake

So it seems I need to fix buildbot user's path but:

buildbot@ip:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

/usr/local/bin is already before /usr/bin, how can I solve this?

I cannot uninstall the cmake package because other packages depend on it and I cannot upgrade it via repositories because last version is not available in 12.04 repos.

Best Answer

The explanation was given by the hash command:

hash command maintains a hash table, which has the used command’s path names. When you execute a command, it searches for a command in the variable $PATH. But if the command is available in the hash table, it picks up from there and executes it.

You can delete a particular command from a hash table using -d option

So I did:

buildbot@ip:~$ hash
hits    command
   3    /usr/bin/which
   1    /usr/bin/vim
   2    /usr/bin/cmake

buildbot@ip:~$ $ hash -d cmake
buildbot@ip:~$ hash
hits    command
   4    /usr/bin/which
   1    /usr/bin/vim
buildbot@ip:~$ cmake --version
cmake version 2.8.7
buildbot@ip:~$ which cmake
/usr/bin/cmake

Why is it not finding /usr/local/bin/cmake?

$ /usr/local/bin/cmake --version
-bash: /usr/local/bin/cmake: Permission denied

So this user didn't have permission to access that file.

I reinstalled cmake and that fixed it.

Related Question