Fix 'bash: command not found' on Linux (path issue)
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
- Find where the command actually lives. Use
whichorwhereis. Example:which dockerorwhereis docker. If it returns nothing, tryfind / -name docker -type f 2>/dev/null— this searches the whole filesystem (may take a minute). Note the full path, like/usr/bin/dockeror/home/you/.local/bin/docker. - 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. - 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. - Make the change permanent. Open your
~/.bashrcfile with a text editor:nano ~/.bashrc. Add this line at the end:export PATH=$PATH:/home/you/.local/bin. Save and exit. Then runsource ~/.bashrcto reload it. - 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) orrpm -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/dockerinstead ofdocker. 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 dockercan put it back in the standard path. - Check for shell aliases or functions. Run
type docker— if it shows something likedocker is a functionordocker is aliased to, then your shell is overriding the actual command. Look in~/.bashrcor~/.bash_aliasesfor 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?