If you receive the error message sudo: command not found’ (or ‘sudo: parancs nem található’ on a Hungarian-language system) after typing ‘sudo’ before a command, the sudo program is not installed on the system. This most commonly occurs on minimal Debian installations, VPSs and in Docker containers: the Debian installer does not install the sudo package if you provided a root password during installation. Ubuntu includes it by default, so the error is rare there.
1. Log in as the root user
You need administrator rights to install sudo. If you have logged in via SSH as the root user, skip to the next step. If you have logged in with your own user account, switch to root:
su -
The program asks for the root user’s password (not your own password). Due to the - switch, you will be granted full root access, meaning that commands under /usr/sbin will also be accessible.
2. Install the sudo package
apt update
apt install sudo
3. Grant sudo privileges to your own user
On Debian and Ubuntu, members of the sudo group can run commands as an administrator. Add your user (replace felhasznalonev with your own username):
usermod -aG sudo felhasznalonev
Group membership only takes effect when you log in again: please log out and log in again. Then check:
groups
sudo whoami
If the second command returns root, the configuration is working. A separate article provides detailed instructions on creating users and granting sudo permissions.
If sudo is installed, you still get an error
- “username is not in the sudoers file”: sudo is working, but the user is not in the
sudogroup. Run the command in step 3 as root. - sudo only runs with the full path (
/usr/bin/sudo): thePATHenvironment variable is incorrect. Use theecho $PATHcommand to check that/usr/binis included, and review the~/.bashrcor~/.profilefile. - In a Docker container: containers usually run as root by default, so
sudoisn’t even needed there; you can simply run the command withoutsudo.
On AlmaLinux and Rocky Linux
On Red Hat-based systems, the package name is the same, but the package manager and group are different:
dnf install sudo
usermod -aG wheel felhasznalonev