sudo: command not found

Fix 'sudo: command not found' on Linux (quick & dirty)

Don't panic when sudo vanishes. Usually it's a PATH issue or missing sudo package. I'll show you the 30-second fix, then the longer ones.

You're in a terminal, type sudo apt install something, and get slapped with bash: sudo: command not found. It's happened to me on more boxes than I care to count — usually on a fresh container, a stripped-down server, or after a PATH got hosed. The culprit here is almost always one of two things: your PATH doesn't include /usr/bin, or the sudo package isn't actually installed. Sometimes it's both.

Let's work through this in order of effort. Start with the 30-second fix, then move up if that doesn't do it. Don't skip ahead and waste 15 minutes when a one-liner solves it.

The 30-Second Fix: Check Your PATH

First thing, figure out if sudo exists at all but just isn't in your PATH. Run this:

which sudo
ls -l /usr/bin/sudo /usr/local/bin/sudo 2>/dev/null

If you get a path back — say /usr/bin/sudo — then the binary is there and the problem is PATH. Check what's in your PATH:

echo $PATH

If you see something like /usr/local/bin:/bin but not /usr/bin, that's your issue. A common culprit is a broken .bashrc or .profile that overwrites PATH. I've seen people accidentally set PATH=/usr/local/bin and wonder why nothing works.

Quick fix: export a sane PATH and test sudo.

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
sudo ls

If that works, edit your shell config to fix it permanently. For bash, that's ~/.bashrc or ~/.profile. Look for any line that sets PATH and make sure it appends, not overwrites. Something like:

export PATH="$PATH:/my/custom/path"

If you're on a minimal system like Alpine, you might be missing /usr/bin from the default PATH entirely — that's normal there, and you might prefer using busybox commands anyway.

No path found? Then move to the moderate fix.

The 5-Minute Fix: Switch to root and install sudo

If sudo isn't installed, you'll need to get root access another way. On most distros, if you know the root password, just do:

su -

Enter the root password. You're now root. If su isn't available either — some containers skip it — you'll need to boot into single-user mode or use your cloud provider's console. But let's assume su works for now.

Once you're root, install sudo using your package manager. Here's the cheat sheet:

DistroCommand
Debian/Ubuntuapt update && apt install -y sudo
CentOS/RHELyum install -y sudo (or dnf on newer)
Fedoradnf install -y sudo
OpenSUSEzypper install sudo
Alpineapk add sudo
Archpacman -Sy sudo

After installation, test it:

sudo ls

Should work now. But there's one more wrinkle: your user might not be in the sudo group (on Debian-based) or wheel (on RHEL-based). If you're the root user testing, that's fine, but for a normal user you need to add them:

usermod -aG sudo yourusername

Or on RHEL/CentOS:

usermod -aG wheel yourusername

Then log out and back in for group changes to take effect.

If you don't know the root password — common on cloud images where only your user has sudo — and sudo is missing, you've got a bigger problem. Skip to the advanced fix.

The 15+ Minute Fix: Recover sudo when you're locked out

This is the nasty scenario: SSH in as a regular user, no root password, and sudo is gone. You're locked out of admin. Happens when someone accidentally removed sudo or your PATH is so broken that even root can't run commands. Here's how to get back in.

First, try to find a root shell via boot options. If you have physical or console access, reboot the machine. In GRUB, highlight the kernel and press e to edit the boot entry. Find the line starting with linux and append single or init=/bin/bash at the end.

For init=/bin/bash, you'll get a root shell directly. For single, you might need to enter the root password. Once you have a root shell, you can remount the filesystem read-write if needed:

mount -o remount,rw /

Then install sudo as above. Also fix that PATH in the user's bashrc while you're there.

No console access? Then you're relying on your cloud provider's rescue mode. AWS, DigitalOcean, and most others offer a recovery console or a rescue ISO. Boot into that, mount your root volume, and chroot in. For example:

mount /dev/sda1 /mnt
chroot /mnt
apt install -y sudo   # or whatever your distro uses

While you're in there, check the sudoers file to make sure your user is still in it:

visudo -c

Look for a line like youruser ALL=(ALL:ALL) ALL or the group include. If it's missing, add it. That's often the real reason sudo stopped working — not the binary, but the config.

Prevent This From Happening Again

Once you're back, a couple of habits will save your butt:

  • Never log in as root for daily work. Use sudo only.
  • Always keep a backup of your PATH in your shell config. Comment out changes.
  • Test commands that modify config files in a VM first.

One real-world trigger: I got bit by this on a CentOS 7 box after a botched Python install that wrote a broken ./bashrc setting PATH to /opt/python/bin. Suddenly sudo wasn't found because /usr/bin was dropped. The 30-second fix saved me that time.

Another: Ubuntu Docker containers often don't have sudo by default. People try to install packages and hit this instantly. The fix is just apt install sudo — no PATH drama.

If you're still stuck, check if sudo is actually a symlink that's broken. ls -l /usr/bin/sudo and verify the target exists. A partial upgrade can leave dangling symlinks.

That's it. Most times it's a PATH problem, and a quick export fixes it. If not, install the package. Rarely you'll need to hack your way in via rescue mode. But now you know the drill.

Related Errors in Linux & Unix
bash: command not found Fix 'bash: command not found' on Linux in 2 Minutes iptables: line 1: Syntax error at position N iptables: line 1: Syntax error at position — rule failed Fix SSH Permission Denied with Public Key Authentication Fix SSH Permission Denied with Public Key Authentication

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.