bash: sudo: command not found

Fix 'bash: command not found' for sudo on Linux

Linux & Unix Beginner 👁 0 views 📅 May 25, 2026

You installed a minimal Linux system and sudo's missing. Here's how to add it back fast.

You're staring at bash: sudo: command not found and it feels like hitting a wall. I've been there — you just installed a fresh minimal server image and the tool everyone assumes is standard simply isn't there. Let's fix it right now.

The one-step fix (using su to become root)

You don't have sudo, but you do have the root password (you set it during install). Here's what to type:

su -

Hit Enter. It'll ask for the root password. Type it (nothing shows as you type — that's normal). After you press Enter, your prompt should change to end with # instead of $. That means you're now the root user.

Now install sudo. The command depends on your Linux distro:

  • Debian / Ubuntu / Mint / Kali: apt update && apt install sudo -y
  • CentOS / RHEL / Fedora / Rocky Linux: dnf install sudo -y (on older CentOS 7: yum install sudo -y)
  • openSUSE: zypper install sudo
  • Arch Linux / Manjaro: pacman -S sudo

After it finishes, type exit to drop back to your normal user. Now test: sudo whoami. It should ask for your password, then print root.

But wait — what if your user isn't in the sudo group yet?

If sudo whoami gives you username is not in the sudoers file. This incident will be reported., don't panic. Become root again (su -) and add your user to the sudo group:

usermod -aG sudo yourusername

Replace yourusername with your actual username. Then log out and back in (or just close and reopen the terminal) for the group change to take effect. Now sudo should work.

Why was sudo missing in the first place?

Minimal install images — especially the netinstall or minimal ISOs — intentionally leave out non-essential packages. The designers assume you'll either use root directly or install exactly what you need. It's not a bug. It's a design choice that trips up anyone coming from a desktop distro where sudo is pre-installed.

The real fix here isn't complicated: you need root privileges to install sudo, and su - is the only way to get them when sudo itself isn't available. Once sudo is installed, you can add your user to the proper group and never think about it again.

Less common variations of this issue

Here are a few tangents I've seen in the field that look like the same error but have different causes:

1. The PATH is broken

If you see bash: sudo: command not found but which sudo or type sudo shows it exists, your PATH environment variable is messed up. Usually happens after editing .bashrc or .bash_profile and accidentally removing /usr/bin or /usr/local/bin. Fix by running export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

2. Using a bare Docker container or WSL

When you pull a Docker image like alpine or debian:stable-slim, sudo is almost never installed. Inside the container, you're usually root already (notice the # prompt). You don't need sudo inside a container — you can run commands directly. If you really want it, apt install sudo works, but it's unnecessary overhead.

3. The sudo binary is there but broken

Rare, but I've seen it. The sudo file exists but permissions are wrong or the binary is corrupted. Run ls -l /usr/bin/sudo. It should have the setuid bit set (-rwsr-xr-x). If it's missing the 's' in the owner section, run chmod u+s /usr/bin/sudo as root.

4. You're in a restricted shell

Some shared hosting or chroot environments lock you into a restricted shell (rbash) where many commands, including sudo, are blocked. If echo $SHELL shows /bin/rbash or similar, you need to contact the system administrator — you can't fix this from inside the restricted shell.

How to prevent this in the future

If you're installing a new Linux system from scratch, always pick the standard or desktop image instead of the minimal one unless you really need to save disk space or bandwidth. The standard images include sudo, a text editor, and basic networking tools out of the box.

If you must use a minimal install (say for a server), add sudo to your post-install checklist right after setting up network connectivity and before creating non-root users. Write yourself a note: Step 1: su -, Step 2: install sudo, Step 3: add user to sudo group. That sequence never fails.

Also consider automating with a configuration management tool like Ansible or a simple shell script. A one-liner like apt install -y sudo && usermod -aG sudo $SUDO_USER can save you the headache next time you spin up a new VM.

Was this solution helpful?