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:
su -
apt update
apt install -y sudosu -
dnf install -y sudosu -
apk add --no-cache sudoInside 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:
# 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 sudoLet your user run sudo
Installing the package is not enough — your account must be in the right group. Still as root:
# Debian/Ubuntu use the "sudo" group
usermod -aG sudo yourname
# RHEL family use "wheel"
usermod -aG wheel yournameGroup membership only applies to new sessions. Log out and back in, then confirm:
sudo whoami # should print: rootRare 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:
echo $PATH
ls -l /usr/bin/sudo
/usr/bin/sudo whoami # call it by full pathNeed 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.