Fixing 'bash: command not found' on Linux – What Actually Works
PATH issues or missing packages cause this. Check your PATH first, then install the package. Don't waste time on wild guesses.
Quick answer
Run echo $PATH to see your current directories. If the command's path isn't listed (e.g., /usr/local/bin), add it with export PATH=$PATH:/new/dir in your ~/.bashrc and reload it with source ~/.bashrc. If the command simply isn't installed, use your package manager (apt install, yum install, etc.).
This error hits everyone at some point. I had a client last month whose entire team couldn't run git on a newly provisioned Ubuntu 22.04 server. Turned out the default PATH was missing /usr/local/git/bin. The real fix was adding that directory, but they'd spent hours reinstalling Git. Don't be that guy.
Why this happens
When you type a command like node or ffmpeg, the shell scans each directory in your PATH variable (a colon-separated list) in order. First match wins. If it finds nothing, you get "command not found". Three common triggers:
- Missing package – You haven't installed the software yet. Obvious but common.
- Broken PATH – You've accidentally overwritten
$PATHin a script or.bashrc, cutting off standard directories. - Permissions – The binary exists but isn't executable for your user.
One real scenario: a developer ran export PATH=/opt/custom in a Dockerfile and then couldn't run ls or cd because the standard system binaries vanished. That's a classic PATH clobber.
Step-by-step fix
- Check your PATH. Run
echo $PATH. Look for directories like/usr/bin,/usr/local/bin,/bin. If you see only one or two entries, that's your problem. - Find the command. Use
which commandnameortype -a commandname. If it returns nothing, the binary isn't in PATH. If it shows a path but the shell still fails, check permissions withls -l /path/to/binary. - Install missing package. On Debian/Ubuntu:
sudo apt update && sudo apt install commandname. On RHEL/CentOS:sudo yum install commandnameorsudo dnf install commandname. For example,ifconfigis often missing on modern distros – installnet-tools. - Fix PATH permanently. Edit
~/.bashrc(or~/.bash_profilefor login shells). Add this line at the end:export PATH=$PATH:/usr/local/bin. Replace with the missing directory. Then runsource ~/.bashrcor log out and back in. - Fix PATH temporarily. For a single session:
export PATH=$PATH:/new/directory. That's handy for testing. - Check for typos. I've spent ten minutes debugging only to realize I typed
nanoasnanoo. Bash is literal.
Alternative fixes if the main one fails
- Use absolute path. If you know where the binary lives, run it directly:
/usr/local/bin/node. This bypasses PATH entirely but is a band-aid, not a cure. - Reinstall the package. Sometimes the package manager leaves broken symlinks. Purge and reinstall:
sudo apt remove --purge packagename && sudo apt install packagename. - Check for snap or flatpak conflicts. On Ubuntu, some commands like
lxdare installed as snaps and masked. Runsnap listto see if the command exists as a snap; you might need to run it with a different name or install the apt version. - Edit system-wide PATH. If multiple users face the issue, edit
/etc/environmentor/etc/profile. Add the path there. Requires root.
Prevention tip
Never start a script or .bashrc with export PATH=/something without including $PATH. Always write export PATH=$PATH:/something. The colon preserves existing entries. I've seen sysadmins break every command on a production server with that one line. Also, test PATH changes in a new terminal before applying them globally. Use echo $PATH after sourcing to confirm.
Was this solution helpful?