Command not found, explained and fixed

When a shell answers bash: frobnicate: command not found (zsh words it “command not found: frobnicate”), it searched every directory in the PATH variable and found no executable file with that exact name. That single fact has four common roots: the program is not installed, the name is misspelled or belongs to a different system, the program exists but its directory is not on the PATH, or the “program” is a file in the current directory, which the shell deliberately does not search.

Work through it in order

  1. Check the name itself: spelling, and whether the command belongs to another environment (ipconfig is Windows, ifconfig or ip is Linux; brew is macOS). Also confirm you typed the command, not its package: the package net-tools provides ifconfig; installing “ifconfig” fails because no package carries that name.
  2. Ask the shell what it knows: type -a name and which name. After a fresh install in the same session, the shell may have cached the old (empty) answer; hash -r clears bash's command cache.
  3. Install it with the system package manager, by the package's real name: sudo apt install <pkg> (Debian/Ubuntu), sudo dnf install (Fedora/RHEL), sudo pacman -S (Arch). Tools like apt-file or dnf provides answer “which package ships this file” precisely.
  4. If it is installed but off PATH (common for ~/.local/bin, language toolchains, and manually unpacked software), either call it by full path or add its directory: export PATH="$HOME/.local/bin:$PATH" in the shell's startup file for permanence.
  5. For a script in the current directory, run it as ./script.sh. The leading ./ is not decoration; the current directory is excluded from PATH on purpose, so a downloaded file cannot shadow system commands.

Special cases that look identical

  1. sudo: xyz: command not found when the plain command works: sudo uses its own secure_path, which omits user directories like ~/.local/bin. Use the full path under sudo, or install the tool system-wide.
  2. “No such file or directory” when running a script that visibly exists: a different error with a different cause, a bad interpreter line (Windows line endings are the classic), covered on its own page.
  3. It worked in another terminal or as another user: PATH is per-user and per-session; compare echo $PATH in both contexts before changing anything.

Common questions

Why does ./ matter for scripts? Shells search PATH directories only. The current directory is not one of them, by design, so ./script.sh (an explicit path) is how you run a local file. Typing the bare name asks the system for an installed command by that name.

I installed it and the same shell still says not found, why? Either the shell cached the negative lookup (hash -r fixes bash), or the package installed its binary into a directory your PATH lacks. type -a after hash -r tells you which.

How do I find which package provides a command? Debian/Ubuntu: apt-file search bin/name (after apt-file update). Fedora/RHEL: dnf provides '*/bin/name'. Arch prints suggestions automatically for many commands via pkgfile. Online package indexes answer it too.

Related errors

No such file or directory · Permission denied (Linux) · 'pip' is not recognized