4

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.

1 Answer 1

5

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.

6
  • This is a partial answer. So Have you tried chmod or chown if it works?
    – user.dz
    Jun 6, 2014 at 11:51
  • 1
    Yes, it didnt work, kept throwing permission denied error. I reinstalled cmake (from sources) and then worked
    – hithwen
    Jun 6, 2014 at 14:34
  • Could you add what fixed problem to your answer, So it will be complete. However, I believe that hash -d cmake would fix it too, Reference How do I clear Bash's cache of paths to executables?
    – user.dz
    Jun 6, 2014 at 15:56
  • hash -d (or -r) fixed the problem of executing one instead of the another. After that I realized that I could not execute the one I wanted, which was a different problem
    – hithwen
    Jun 7, 2014 at 9:03
  • Well, what are the permissions of /usr/local/bin/cmake, then?
    – fkraiem
    Nov 7, 2016 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .