command not found

Fix 'bash: command not found' on Linux When the Command Exists

The shell can't locate a program even though it's installed. Usually a PATH issue or a missing shell hash. Here's how to fix it fast.

Quick answer: Run type command to see what the shell thinks, then check your PATH with echo $PATH. If the binary's directory isn't there, add it to ~/.bashrc. If it is, run hash -r to clear the shell's command cache.

I know this error is infuriating. You just installed something, or maybe you've used it for months, and suddenly bash: command not found pops up. The program is sitting right there in /usr/bin, but the shell swears it doesn't exist. This tripped me up the first time too, back when I was messing with a custom Python install on Ubuntu 16.04. The fix is usually boring and quick, but it's worth understanding what's going on so you can solve it in seconds next time.

The shell finds commands by searching a list of directories stored in the PATH environment variable. If the directory containing the executable isn't in that list, the shell won't look there. Also, bash keeps a hash table of recently executed commands for speed — if you moved or deleted a file, the hash can point to the wrong place. Both issues produce the same confusing message.

Step-by-step Fix

  1. Find the actual path to the command. Use which or type. For example:
    which python3
    If that returns nothing, the tool might be in a non-standard location. Try find / -name python3 -type f 2>/dev/null — this searches the whole system, but give it a minute.
  2. Check your PATH variable. Run:
    echo $PATH
    Look for the directory from step 1. If it's missing, that's your problem. For instance, if the binary lives in /usr/local/bin and that directory isn't listed, the shell can't find it.
  3. Add the directory to PATH. Open your ~/.bashrc file and add this line (adjust the path to match your situation):
    export PATH="/usr/local/bin:$PATH"
    Save the file, then run source ~/.bashrc to apply the change immediately. For system-wide changes, edit /etc/environment instead, but that's overkill for most cases.
  4. Clear the bash hash table. If the command was in PATH and still fails, the hash might be stale. Run:
    hash -r
    This wipes the cached locations. Try the command again.
  5. Test it. Run your command. If it works, you're done. If not, move to the alternatives below.

If That Doesn't Work

Sometimes the issue is more specific. Here are a few other culprits I've seen:

  • Wrong shell. If you're using zsh or fish, your bashrc edits won't apply. Check with echo $SHELL and edit the right config file (~/.zshrc for zsh, ~/.config/fish/config.fish for fish).
  • Executable permission missing. The file exists, but it's not marked as executable. Fix with chmod +x /path/to/command.
  • Symbolic link broken. The command is a symlink pointing to a non-existent file. Use ls -l $(which command) to check. If you see a red flashing link, recreate it with ln -s /real/path /usr/local/bin/command.
  • Environment override. Some scripts set PATH to a minimal value. If this happens inside a specific script, run source ~/.bashrc after that script runs, or export the full PATH at the top of your script.

Prevention Tips

To stop this from happening again, keep a few habits:

  • Always install programs to standard locations like /usr/local/bin and make sure that's in your PATH.
  • After installing via source or a custom script, run hash -r before freaking out.
  • If you edit ~/.bashrc, run source ~/.bashrc instead of opening a new terminal — it's faster and catches typos immediately.

This error is rarely serious, but it can stall you. Now you've got the tools to squash it in under a minute. The next time you see "command not found," you'll know exactly where to look.

Related Errors in Linux & Unix
command not found Fix 'bash: command not found' on Linux – Real Fixes Permission denied (publickey) Fix 'Permission denied' (SSH public key) in Linux Swap partition not active? Here's how to fix it fast Permission denied (publickey) Linux 'Permission Denied' fix for SSH public key login

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.