command not found

Fix 'bash: command not found' on Linux (PATH reset fix)

Linux & Unix Beginner 👁 1 views 📅 May 30, 2026

When bash can't find a command, it's usually a broken PATH or missing package. Here's how to fix it fast.

When does this error pop up?

You type a basic command like ls, sudo, or vi, and bash says command not found. It happens right after you mess with your .bashrc, .profile, or .bash_profile. Or maybe you installed something from source and accidentally overwrote PATH instead of appending to it. I had a client last week who copied a script from a forum that had export PATH=/some/custom/dir instead of export PATH=$PATH:/some/custom/dir. Boom — everything broke.

What's actually going on?

The PATH environment variable tells bash where to look for executable files. It's a colon-separated list of directories like /usr/local/bin:/usr/bin:/bin. When you set PATH to a single directory, you lost access to all the standard system commands. Bash can't find ls because /bin isn't in the list anymore. Same for sudo in /usr/bin.

The fix is to restore PATH to a sensible default that includes the standard directories.

The fix — step by step

Most of these steps work on Ubuntu, Debian, CentOS, or any modern Linux. The exact default PATH varies a little by distro, but I'll give you the one that works everywhere.

  1. Open a new terminal or reconnect via SSH.
    If you're stuck in a broken shell session, just open a new one. The default PATH is usually set in /etc/profile and /etc/environment, which still load. That alone might fix it. Try typing echo $PATH — if your path looks like /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin, you're good. If it's just one entry, keep reading.
  2. If you can't even open a new terminal, use the absolute path.
    Type /bin/ls or /usr/bin/sudo to run commands by their full path. That bypasses PATH entirely. Once you're in, you can fix the file that broke it.

    /bin/cat ~/.bashrc

    Look for a line like export PATH=/something that doesn't include $PATH.
  3. Fix the offending file.
    Edit your .bashrc (or .profile or .bash_profile — whichever you changed):
    /usr/bin/nano ~/.bashrc

    Find the line that sets PATH without the $PATH variable. Change it from:
    export PATH=/custom/dir

    to:
    export PATH=/custom/dir:$PATH

    Or just comment it out with a # at the start if you don't need it.
  4. Source the file or restart the shell.
    source ~/.bashrc

    Or just close and reopen the terminal. Your PATH should be back to normal.
  5. If you don't know which file broke it, check them all.
    Run these one by one to find the culprit:
    /bin/grep 'export PATH' ~/.bashrc ~/.profile ~/.bash_profile /etc/profile

    Look for any line that sets PATH without $PATH in it.

What if it's still broken?

Sometimes the file itself got corrupted or deleted. Here's what to do next:

  • Restore .bashrc from the system skeleton. Most distros keep a default in /etc/skel/. Copy it over:
    /bin/cp /etc/skel/.bashrc ~/.bashrc

    Then source it.
  • Check /etc/environment. Some systems set PATH there. It should look like PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin". If it's wrong, fix it with sudo (using absolute path):
    /usr/bin/sudo /usr/bin/nano /etc/environment
  • If sudo itself says command not found, you need to become root via another method. Use su - (with the hyphen to load root's profile), or boot into recovery mode. Once you're root, run export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin to get everything working again.

Had a client once who edited /etc/environment from a script and left a trailing quote. The whole system couldn't find any commands. We booted from a live USB, mounted the drive, and fixed the file. Takes 10 minutes and saves a reinstall.

Bottom line: always append to PATH, never overwrite it. If you do break it, these steps will get you back up in five minutes flat.

Was this solution helpful?