sudo: command not found — Fix for Debian, Docker & VPS
sudo: command not found means the sudo binary is not installed or is not in your PATH. This is common on minimal Debian installations, Docker containers, and some VPS base images that only include root access.
Quick Diagnosis
which sudo
# If output is empty, sudo is not installed
echo $PATH
# Check if /usr/bin is in PATH
Fix 1: Install sudo (as root)
If you are logged in as root (the case on most fresh VPS setups):
apt update && apt install -y sudo
Then add your non-root user to the sudo group:
usermod -aG sudo YOUR_USERNAME
Log out and back in for the group change to take effect, then verify:
sudo whoami
# Should output: root
Fix 2: sudo Not in PATH
If sudo is installed but still not found, it may not be in the current user's PATH. This can happen after su without a login shell:
# Use full path
/usr/bin/sudo apt update
# Or start a proper login shell
su - root
Always use su - (with the dash) rather than su to load the target user's full environment including PATH.
Fix 3: Docker Containers
Docker containers built from minimal base images (debian:slim, ubuntu:minimal, alpine) typically do not include sudo. The recommended approach in Dockerfiles is to run as root for setup, then switch to a non-root user:
FROM debian:12-slim
RUN apt-get update && apt-get install -y sudo \
&& useradd -m appuser \
&& echo "appuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& rm -rf /var/lib/apt/lists/*
USER appuser
Alternatively, perform all privileged operations in the RUN steps (as root) before switching users — this avoids needing sudo in the container at all.
Fix 4: Alpine Linux
Alpine uses doas instead of sudo by default, and sudo is a separate package:
apk add sudo
# or use doas:
apk add doas
echo "permit nopass YOUR_USERNAME" > /etc/doas.d/doas.conf
Adding sudoers Entry Without the Group
For fine-grained control, edit /etc/sudoers via visudo (never edit it directly):
visudo
Add one of these lines:
# Full sudo access
username ALL=(ALL:ALL) ALL
# No password required (convenient but less secure)
username ALL=(ALL) NOPASSWD:ALL
# Only allow specific commands
username ALL=(ALL) NOPASSWD:/usr/bin/apt, /usr/bin/systemctl
VPS Note
On VMHeaven VPS instances you receive root access directly. If you create non-root users for daily operations (recommended for security), install sudo and configure it as shown above so those users can perform administrative tasks without switching to root.