What the message looks like
bash: docker-compose: command not foundCommon causes
- The program is not installed, or the package name differs from the command name.
- The directory holding the program is missing from
PATH, for example/usr/sbinfor a regular user on Debian, or~/.local/bin. - A typo or wrong capitalisation in the command name.
- A script in the current directory is called without
./; the current directory is not in PATH. - Under
sudo,suor cron a different, shorter PATH applies than in the interactive shell.
Check
- Where is the command and which variants exist?
type -a docker-compose; command -v docker-compose - Show the current PATH, one entry per line
echo "$PATH" | tr ':' '\n' - Which package ships the file? (Debian/Ubuntu, needs apt-file)
apt-file search --regexp 'bin/docker-compose$' - Compare PATH under sudo
sudo sh -c 'echo $PATH'
Fix
- Rule out typos and check the name with tab completion.
- Install the missing program, for example with
apt install packagename; on Ubuntu thecommand-not-foundhint helps if it is installed. - If the file exists but lies outside PATH, add the folder:
export PATH="$PATH:/usr/sbin", made permanent in~/.profileor~/.bashrc. - After installing or moving a program, clear the shell's hash cache:
hash -r. - Call scripts with
./script.shor an absolute path; in cron jobs and scripts use absolute paths or set PATH at the top.
Typical scenario
After a fresh Debian install someone types ifconfig or iptables as a regular user and gets command not found, although the package is installed. The binary lives in /usr/sbin, which is not in the PATH of users who did not use su -. With sudo iptables -L or the full path /usr/sbin/iptables the command runs immediately.
FAQ
What does exit code 127 mean?
127 is the shell's usual exit code for "command not found". It differs from 126, which means "found but not executable", for example because of missing permissions.
Why does it fail as root but work as a user?
Because root and regular users can have different PATH values. Under sudo, secure_path from the sudoers file applies instead of the user's PATH.
How do I tell whether PATH alone is to blame?
Check whether the file exists with ls /usr/sbin/command or find / -name command -type f 2>/dev/null. If it is found but command -v shows nothing, only the path is missing.
Why can't cron find my program?
Cron starts with a minimal PATH, usually just /usr/bin:/bin. Either use absolute paths or put a PATH=... line at the top of the crontab.
I just installed the command and it is still not found. Why?
The shell remembers locations in its hash cache. hash -r or a new shell session triggers a fresh lookup. For installs into ~/.local/bin that folder also has to be in PATH.