Ubuntu/Debian – Fixing the “sudo: command not found” error

Linux 2 min read

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 sudo group. Run the command in step 3 as root.
  • sudo only runs with the full path (/usr/bin/sudo): the PATH environment variable is incorrect. Use the echo $PATH command to check that /usr/bin is included, and review the ~/.bashrc or ~/.profile file.
  • In a Docker container: containers usually run as root by default, so sudo isn’t even needed there; you can simply run the command without sudo.

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
Back: Linux articles (62)