sudo: command not found

Fix 'sudo: command not found' When sudo Is Installed

sudo exists but the shell can't find it? Likely a PATH issue or missing symlink. Here's how to fix it fast, plus edge cases.

I know this error is infuriating—you're staring at a terminal that says sudo: command not found, you know sudo is installed, and yet the shell won't cooperate. It's happened to me more times than I care to admit, usually right after I've messed with my PATH or moved some binaries around. Good news: it's almost never a broken sudo. Let's fix it.

The quick fix: use the full path

If sudo is installed but your shell just can't find it, you can call it by its absolute path. Most Linux distros put sudo in /usr/bin/sudo, but some (like older CentOS or RHEL) put it in /usr/sbin/sudo. Try this:

/usr/bin/sudo -v

If that returns without error, sudo works. Now you can run any command with the full path:

/usr/bin/sudo apt update

But typing /usr/bin/sudo every time is a pain. Here's the permanent fix:

Step-by-step: fix your PATH

  1. Check what your PATH currently includes:
  2. echo $PATH
  3. Look for /usr/bin or /usr/sbin—if they're missing, that's the root cause.
  4. Add them back. If you're using bash, edit ~/.bashrc or /etc/profile (for system-wide changes). Add this line if it's not there:
  5. export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  6. Reload your shell config:
  7. source ~/.bashrc

If you're using zsh, replace ~/.bashrc with ~/.zshrc. Test again with sudo -v.

Why this happens (and why it's your PATH's fault)

Your shell finds commands by searching through directories listed in the PATH environment variable. If /usr/bin isn't in that list, the shell can't find sudo—even though it's right there. This usually comes from one of these:

  • You (or a script) accidentally overwrote PATH in a profile file.
  • A package manager or install script modified your PATH badly.
  • You're in a restricted environment like a cron job or a minimal container where PATH is stripped down.

I've seen this happen right after someone installs Python or Node.js via a script that prepends its own path and truncates the rest. It's a classic.

Other causes and their fixes

Sudo isn't actually installed

Sometimes it's not just a PATH issue—sudo might be missing entirely. In that case, switch to root (if you know the root password) or use su - to become root, then install sudo:

apt install sudo   # Debian/Ubuntu
yum install sudo    # RHEL/CentOS

If you don't have root access either, you're stuck until the admin fixes it—but at least you'll know.

Missing symlink

On some systems, sudo might be installed in /usr/bin but the symlink got deleted. Check with ls -l /usr/bin/sudo. If it's a broken symlink, recreate it:

ln -s /usr/bin/sudo /usr/local/bin/sudo

But be careful—if you recreate a symlink to a location that isn't in your PATH, it won't help. Make sure the target directory is in your PATH.

Shell-specific quirks

If you're using a non-standard shell like fish or tcsh, the syntax for setting PATH differs. For fish:

set -gx PATH /usr/bin /usr/sbin $PATH

Prevention: stop it from happening again

Once you've fixed your PATH, lock it down so this doesn't recur. My advice:

  • Always back up your ~/.bashrc (or ~/.zshrc) before editing.
  • Avoid installing software with scripts that modify PATH—read the script first if you can.
  • When you're testing something that changes environment variables, do it in a subshell: bash then test, then exit.
  • For system-wide changes, use /etc/profile or files in /etc/profile.d/—they're cleaner to manage and less likely to get clobbered.

You don't need to memorize this fix forever, but knowing that /usr/bin/sudo is your escape hatch will save you next time. And if you're ever in a situation where sudo is genuinely broken, you'll know to check the binary, not your patience.

Related Errors in Linux & Unix
command not found Command Not Found After Installing Package on Linux NetworkManager restart loop fix: 3 real causes E: dpkg was interrupted Fix dpkg Interrupted Error: Run dpkg --configure -a Fix 'Permission Denied' on Linux: 3 Causes & Solutions

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.