bash: command not found

Fixing 'bash: command not found' on Linux – What Actually Works

Linux & Unix Beginner 👁 8 views 📅 May 29, 2026

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 $PATH in 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

  1. 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.
  2. Find the command. Use which commandname or type -a commandname. If it returns nothing, the binary isn't in PATH. If it shows a path but the shell still fails, check permissions with ls -l /path/to/binary.
  3. Install missing package. On Debian/Ubuntu: sudo apt update && sudo apt install commandname. On RHEL/CentOS: sudo yum install commandname or sudo dnf install commandname. For example, ifconfig is often missing on modern distros – install net-tools.
  4. Fix PATH permanently. Edit ~/.bashrc (or ~/.bash_profile for login shells). Add this line at the end: export PATH=$PATH:/usr/local/bin. Replace with the missing directory. Then run source ~/.bashrc or log out and back in.
  5. Fix PATH temporarily. For a single session: export PATH=$PATH:/new/directory. That's handy for testing.
  6. Check for typos. I've spent ten minutes debugging only to realize I typed nano as nanoo. 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 lxd are installed as snaps and masked. Run snap list to 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/environment or /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?