7

I installed 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 /usr/local/bin/:

$ 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,

$ 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 /usr/local/bin?

It might be relevant that I previously installed docker-compose via apt, but I have removed and purged this package.

6
  • unix.stackexchange.com/questions/5609/…
    – Bob
    Jul 12, 2019 at 13:35
  • 2
    Try hash docker-compose, explanation here.
    – harrymc
    Jul 12, 2019 at 13:36
  • @harrymc That's exactly the problem and the solution. Thanks! And thanks for the link, I hadn't found that one. Jul 12, 2019 at 13:45
  • Note that in such cases it is customary to ask the person who furnished the solution to also give the answer.
    – harrymc
    Jul 12, 2019 at 13:48
  • @harrymc Please do so and I'll accept it the answer. I posted my answer based on a result from Reddit before I saw your comment. Jul 12, 2019 at 13:49

4 Answers 4

12

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 in memory. 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 hash command.

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:

 hash docker-compose
0

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:

https://github.com/docker/compose/issues/3371#issuecomment-381162525 https://unix.stackexchange.com/questions/82991/bash-is-not-finding-a-program-even-though-its-on-my-path

0

After installing Docker using Snap, you removed docker from snap and installed without snap, but still the path points to the location /snap/bin/docker, so if you get this error, update the value of PATH to get the expected output.

0

I removed an existing docker using snap and installed the latest docker. And I see the same issue. I was tried to run "hash docker-compose", but my system can not find "hash" command. I just close my terminal and reopen another terminal, the problem disappeared.

You must log in to answer this question.

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