bash: command not found

Fix 'bash: command not found' on Linux — Root Causes

Linux & Unix Beginner 👁 15 views 📅 May 26, 2026

This error means bash can't locate the command you typed. Usually a PATH issue, typo, or missing package. I'll show you how to fix it fast.

Quick Answer

Run echo $PATH to check your PATH. If the command's directory (like /usr/local/bin) is missing, add it with export PATH=$PATH:/usr/local/bin. Then run hash -r and try again. If that fails, the package isn't installed — use apt install or yum install to grab it.

Why This Happens

I've seen this error a thousand times on forums and in my own terminal. It's frustrating because you know you typed the right command. Bash looks for executables in every directory listed in your PATH variable, in order. If your command isn't in any of those directories, or if you mistyped the name (trust me, I've hit sudu instead of sudo more times than I'll admit), bash throws up its hands.

Common triggers: you just installed a new tool but its binary landed in /usr/local/bin, which isn't in your default PATH. Or you're on a stripped-down Docker container or minimal server image that doesn't include common utilities like ifconfig or telnet. On CentOS 7, for instance, ifconfig isn't installed by default — you need net-tools. Ubuntu 22.04 LTS dropped ifconfig entirely, pushing you to ip. So knowing the exact trigger matters.

How to Fix It — Step by Step

  1. Check for typos. I know it sounds dumb, but I've wasted 10 minutes on a typo before. Retype the command slowly. Case matters on Linux — Ls isn't ls.
  2. Print your PATH. Run echo $PATH. You'll see a colon-separated list. Common entries: /usr/local/sbin, /usr/local/bin, /usr/sbin, /usr/bin, /sbin, /bin. If the directory containing your command is missing, that's the problem.
  3. Locate the command. Use which commandname or type commandname. If it returns nothing, the command isn't installed. If it returns a path like /opt/myapp/bin/commandname, that directory must be in your PATH.
  4. Add the directory to PATH temporarily. export PATH=$PATH:/opt/myapp/bin. This only lasts for the current session. Test the command again.
  5. Make it permanent. Edit your shell profile — ~/.bashrc for bash, ~/.zshrc for zsh. Add the same export PATH line at the end. Then source ~/.bashrc to reload.
  6. Rehash the command cache. Bash caches command locations. Run hash -r to clear it. Without this, bash might still complain even after fixing PATH.
  7. Install the missing package. If the command doesn't exist at all, install it. For Debian/Ubuntu: sudo apt update && sudo apt install packagename. For RHEL/CentOS/Fedora: sudo yum install packagename or sudo dnf install packagename. Need to know the package? Search with apt search commandname or yum whatprovides */commandname.

Alternative Fixes If the Main One Fails

Sometimes PATH is correct, the command is installed, and it still fails. Here's what to try next:

  • Use the full path. If you know where the binary lives, call it directly: /usr/local/bin/commandname. If it works, the issue is definitely PATH. Add that directory.
  • Check file permissions. Run ls -l /path/to/command. If it doesn't have execute permission (-rwxr-xr-x), add it with chmod +x /path/to/command.
  • Verify the shell is bash. Run echo $SHELL. If it shows /bin/sh or something else, you might be in a different shell. Switch to bash with bash or chsh -s /bin/bash.
  • Check for broken symlinks. Use readlink -f /path/to/command. If it returns a path that doesn't exist, the symlink is dead. Reinstall the package.
  • Try a subshell. Sometimes environment variables get messed up. Launch a fresh subshell with bash -l and see if the command works there.

Prevention Tip

Before you install a new tool, read the docs to see where the binary lands. I always add /usr/local/bin and ~/bin to my PATH in ~/.bashrc right after I set up a new system. And I keep a list of common packages I need — net-tools, traceroute, nano, curl, git — and install them immediately on a fresh install. That way, the 'command not found' error is rare from day one.

Also, set up a bash alias for debugging: alias path='echo $PATH | tr ":" "\n"' — this prints each directory on a new line. Makes spotting missing paths trivial.

Was this solution helpful?