docker-compose on my Ubuntu 16.04 machine following the instructions at https://docs.docker.com/compose/install/ to use
curl to download the binary directly to
$ ls -lh /usr/local/bin/docker-compose -rwxr-xr-x 1 root root 16M Jul 11 15:55 /usr/local/bin/docker-compose
/usr/local/bin/ is in my PATH:
$ echo $PATH /home/me/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Note that it comes before
/usr/bin, in fact.
When I try to check its version, I get what seems to be a PATH-related error:
$ docker-compose --version bash: /usr/bin/docker-compose: No such file or directory
I get the correct behavior either by specifying the full path of the executable,
$ /usr/local/bin/docker-compose --version
docker-compose version 1.24.0, build 0aa59064
or by using
$ sudo docker-compose --version docker-compose version 1.24.0, build 0aa59064
Why can't I run
$ docker-compose --version? Why does Bash complain about
/usr/bin in particular, when it ought to find the executable in
It might be relevant that I previously installed
apt, but I have removed and purged this package.
The problem seems to be an existing location entry from the previous installation, which
apt-get remove and
apt-get purge did not remove or purge.
hash docker-compose removes the entry. More information can be found here:
You have installed docker-compose once in one place. Then you deleted it and installed it in another location.
In that way, you have run into an optimization of bash for not
having to search $PATH every time you type a command, by caching the results
The path hash is a hash-table, maintained by bash, that contains the locations
on disk where the shell should look for executable programs when a command is run.
The hash table gets cleared on events that obviously invalidate the results (such as modifying $PATH), or by using the inbuilt
When you executed docker-compose again, bash just tried to get it from where it found it the last time, only that it wasn't there any more, so you got that error message.
To invalidate the hash for docker-compose, run the command: