VMHeaven

Troubleshooting

sudo: command not found — install it the right way

sudo is missing on many minimal images and containers. How to install it as root, add your user to the right group, and what to do with no root access.

Updated 08 Aug 2026~5 min read

sudo: command not found is common on minimal Debian installs, container base images and freshly provisioned servers. sudo simply is not part of the base system there. The catch: to install it you usually need root, which is exactly what sudo gives you — so you install it as root first.

Become root, then install sudo

If you know the root password, switch to root and install the package:

Debian · Ubuntu
su -
apt update
apt install -y sudo
RHEL · Rocky · Alma · Fedora
su -
dnf install -y sudo
Alpine
su -
apk add --no-cache sudo

Inside a Docker container you are already root

Most base images run as root, so there is no need for sudo at all — drop it from your commands:

Dockerfile
# instead of: RUN sudo apt install -y curl
RUN apt-get update && apt-get install -y curl

# if a script insists on sudo, install it:
RUN apt-get update && apt-get install -y sudo

Let your user run sudo

Installing the package is not enough — your account must be in the right group. Still as root:

grant sudo
# Debian/Ubuntu use the "sudo" group
usermod -aG sudo yourname

# RHEL family use "wheel"
usermod -aG wheel yourname

Group membership only applies to new sessions. Log out and back in, then confirm:

verify
sudo whoami   # should print: root

Rare case: sudo is installed but still not found

If which sudo finds nothing but the package is present, /usr/bin may be missing from a stripped-down PATH:

check PATH
echo $PATH
ls -l /usr/bin/sudo
/usr/bin/sudo whoami   # call it by full path

Need a clean environment to reproduce a minimal-image issue? A Standard KVM VPS deploys from stock images in about a minute and bills monthly.

Frequently asked

How do I install sudo if I need sudo to install it?

You do not use sudo — switch to root with 'su -' (or your provider's root login) and install the package directly, then add your user to the sudo/wheel group.

Do I need sudo inside a Docker container?

Usually not — most base images already run as root, so drop the sudo from your commands. Install it only if a script insists on it.

I installed sudo but my user still cannot use it — why?

Group membership only applies to new sessions, and the account must be in the 'sudo' group (Debian/Ubuntu) or 'wheel' (RHEL). Add it, then log out and back in.

More in Troubleshooting

See all