bash: command not found

Fix 'bash: command not found' on Linux (path issue)

Linux & Unix Beginner 👁 0 views 📅 May 25, 2026

A short, plain fix for when Linux can't find a command you know is installed. It's almost always a PATH problem.

Quick answer

Run echo $PATH to see your current path. If the directory containing the command isn't listed, add it with export PATH=$PATH:/usr/local/bin (or wherever the command lives). Then run source ~/.bashrc to reload.

Why this happens

This error shows up when you type a command like docker, pip, or nano and the shell says it can't find it. But you know you installed it. Maybe you used apt install or pip install --user, and the binary ended up in a directory that's not in your PATH.

The PATH is just a list of directories the shell searches when you type a command. If the directory with the binary isn't in that list, the shell gives up and throws that error. This is especially common after installing software with pip install --user (which puts binaries in ~/.local/bin) or after compiling from source (defaults to /usr/local/bin).

I've seen this trip up new Linux users constantly. It's not that the system is broken. It just doesn't know where to look.

Step-by-step fix

  1. Find where the command actually lives. Use which or whereis. Example: which docker or whereis docker. If it returns nothing, try find / -name docker -type f 2>/dev/null — this searches the whole filesystem (may take a minute). Note the full path, like /usr/bin/docker or /home/you/.local/bin/docker.
  2. Check your current PATH. Run echo $PATH. You'll see something like /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. Look at that list. Does it include the directory you found in step 1? If not, that's your problem.
  3. Add the missing directory to your PATH temporarily. Run export PATH=$PATH:/home/you/.local/bin (replace with the actual directory). Then try the command again. It should work now. This change is only for the current terminal session.
  4. Make the change permanent. Open your ~/.bashrc file with a text editor: nano ~/.bashrc. Add this line at the end: export PATH=$PATH:/home/you/.local/bin. Save and exit. Then run source ~/.bashrc to reload it.
  5. Test again. Close and reopen the terminal, or just type the command again. It should work now.

Alternative fixes (if the main one doesn't help)

  • Check if the command is actually installed. Sometimes you think you installed it but didn't. Run dpkg -l | grep docker (for Debian/Ubuntu) or rpm -qa | grep docker (for Red Hat/Fedora). If it's not listed, install it properly.
  • Use the full path. If you're in a hurry, just type the full path: /usr/bin/docker instead of docker. That bypasses the PATH lookup entirely. Ugly, but it works.
  • Reinstall the package. Sometimes the binary gets installed but in a weird location. Reinstalling with sudo apt install --reinstall docker can put it back in the standard path.
  • Check for shell aliases or functions. Run type docker — if it shows something like docker is a function or docker is aliased to, then your shell is overriding the actual command. Look in ~/.bashrc or ~/.bash_aliases for the alias and remove it.

Prevention tip

After installing any command-line tool, always check if it works immediately. If it doesn't, run echo $PATH and see where the binary went. Over time, you'll build a mental map of where different package managers put things: apt puts system-wide binaries in /usr/bin, pip install --user goes to ~/.local/bin, and npm install -g often goes to /usr/local/bin or /usr/lib/node_modules/.bin. Knowing these defaults saves you time.

Also, consider adding common directories to your PATH in ~/.bashrc proactively. I add ~/.local/bin and ~/bin right after the standard PATH. Then you rarely hit this error.

Was this solution helpful?