QuickPrototype QuickPrototype - 1 month ago 18
Bash Question

Does Unix Cache Binaries?

This is a question for my understanding, I believe that *nix systems rarely required reboot. i.e. if you installed a new "application" or even kernal 9/10 no reboot is required.

I recently installed a random component (liquidsoap dependency) I required from source: camlp4-4.03-1 and noticed the following:

pi@raspberrypi:~ $ /usr/local/bin/camlp4 -v
Camlp4 version 4.03.0
pi@raspberrypi:~ $ camlp4 -v
Camlp4 version 4.01.0
pi@raspberrypi:~ $ which camlp4
/usr/local/bin/camlp4


I am stumped as to the version mismatch? for what appears to be the same file?
There is no "camlp4" in the present directory :)

HW: Raspberry Pi 3
OS: Raspbian Jessie (up to date)




Information Requested Added:

pi@raspberrypi:~ $ find / -name camlp4
/usr/local/lib/ocaml/site-lib/camlp4
/usr/local/lib/ocaml/camlp4
/usr/local/bin/camlp4
/usr/lib/ocaml/camlp4
/usr/share/doc/camlp4
/usr/bin/camlp4
/home/pi/apps/camlp4
/home/pi/apps/camlp4/camlp4-4.03-1/_build/camlp4
/home/pi/apps/camlp4/camlp4-4.03-1/camlp4
/home/pi/apps/ocamlfind/findlib-1.6.2/site-lib-src/camlp4

pi@raspberrypi:~ $ type -a camlp4
camlp4 is /usr/local/bin/camlp4
camlp4 is /usr/bin/camlp4

pi@raspberrypi:~ $ which camlp4
/usr/local/bin/camlp4
pi@raspberrypi:~ $ /usr/bin/camlp4 -v
Camlp4 version 4.01.0
pi@raspberrypi:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games





Testing Solution provided:

pi@raspberrypi:~ $ /usr/local/bin/camlp4 -v
Camlp4 version 4.03.0
pi@raspberrypi:~ $ camlp4 -v
Camlp4 version 4.01.0
pi@raspberrypi:~ $ which camlp4
/usr/local/bin/camlp4
pi@raspberrypi:~ $ hash -r
pi@raspberrypi:~ $ camlp4 -v
Camlp4 version 4.03.0

Answer

most shells indeed maintain a cache of the binary to launch for a given command, in order to avoid searching through the PATH everytime, and which does not know about this cache, which explain the discrepancy you're observing. The way to refresh the cache differs from a shell to another. For bash or dash, you should do hash camlp4. For zsh, this is rehash.

Comments