Error message
bash: command: command not found
The shell searched every directory in your PATH and found no executable with that name.
Quick diagnosis
Start here. This one command usually tells you which of the causes below you are dealing with:
$ which command 2>/dev/null || echo "not on PATH"; echo $PATH | tr ":" "\n" Tells you in one line whether the command exists on your PATH, and shows exactly which directories the shell is searching.
Causes, ordered by how often they are the culprit
1 The program is not installed (most common)
Nothing exotic: the tool simply is not on this machine. Minimal server images and containers ship with surprisingly little.
$ apt list --installed 2>/dev/null | grep -i name $ sudo apt install name The package name often differs from the command: `dig` comes from dnsutils, `ifconfig` from net-tools, `ping` from iputils-ping. If apt cannot find it, search: apt search name.
2 It is installed, but its directory is not on PATH
Common with tools installed to ~/.local/bin, /opt, or by language package managers (pip --user, npm -g, cargo, go install). The binary exists; the shell does not know where to look.
$ find / -name "thecommand" -type f 2>/dev/null | head $ export PATH="$HOME/.local/bin:$PATH" That lasts for the current shell only. Add the same line to ~/.bashrc to make it permanent, then `source ~/.bashrc`.
3 You are running it as sudo and sudo has a different PATH
sudo resets PATH for security (secure_path in /etc/sudoers). A command that works as you can vanish under sudo.
$ which thecommand && sudo which thecommand $ sudo /full/path/to/thecommand Or use sudo env "PATH=$PATH" thecommand when you understand the implications.
4 The script is in the current directory
Unlike Windows, Linux does not search the current directory for security reasons — otherwise a malicious file named `ls` in a shared folder would run instead of the real one.
$ ls -l ./thescript.sh $ ./thescript.sh And it must be executable: chmod +x thescript.sh.
5 A typo, or the tool has been renamed
Some classics were replaced: ifconfig by ip, netstat by ss, service by systemctl. Old tutorials still teach the retired names.
$ compgen -c | grep -i part-of-the-name | sort -u | head $ ip addr # instead of ifconfig 6 You edited PATH and broke it
A malformed line in ~/.bashrc (a missing $PATH in the assignment) can wipe your search path, and suddenly *everything* is "command not found" — even ls.
$ echo $PATH $ export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin That restores a working PATH for the current session. Then fix the offending line in ~/.bashrc — remember the pattern is PATH="new/dir:$PATH", never PATH="new/dir".
How to stop it happening again
- When adding directories to PATH, always keep the old value: export PATH="$HOME/bin:$PATH".
- Use `type -a name` rather than `which`: it also reveals aliases, functions and shell builtins, which is the full truth about what runs.
- In scripts, test for dependencies up front: command -v jq >/dev/null || { echo "jq required" >&2; exit 1; }.
- After installing something in a shell you already had open, run `hash -r` — the shell caches command locations.
Frequently asked questions
Why does it work for me but not with sudo?
sudo replaces PATH with a restricted secure_path. Give the full path to the binary, or install the tool into a system directory such as /usr/local/bin.
Why do I have to type ./script.sh instead of script.sh?
The current directory is deliberately not on PATH. If it were, dropping a malicious file called `ls` into a shared directory would hijack the real command for anyone who ran it there.
I installed it with pip/npm and it still is not found
Those install into user directories (~/.local/bin, ~/.npm-global/bin) that are often not on PATH by default. Add the directory to PATH in ~/.bashrc.
Suddenly EVERY command says "not found" — what happened?
You almost certainly overwrote PATH instead of appending to it. Restore it for this session with export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin, then fix ~/.bashrc.
Commands involved
Which binary actually runs when you type a name — and unmask aliases.
env & exportHow configuration flows into processes — PATH, export, and why edits "don't stick".
aptSearch, install, upgrade and remove packages — plus the dnf/pacman equivalents.
chmodChange file permissions with numeric (755, 644) and symbolic (u+x) modes — clearly explained.
Concepts behind this error: PATH · Shell · Environment variable
Other errors
SSH rejected your login because no key you offered was accepted by the server.
No such file or directoryThe path you gave does not resolve — but often the missing part is not the one you think.
Permission deniedThe path resolves fine — the system simply will not let you do that with it.
No space left on deviceA filesystem is full — confirm which one, and whether you ran out of bytes or inodes.