How to Fix 'sudo: command not found' After a Fresh Linux Server Setup

A sysadmin guide to resolving the 'sudo: command not found' error on fresh Ubuntu, Debian, and CentOS/RHEL VPS installations by installing sudo and configuring sudoers correctly.

How to Fix 'sudo: command not found' After a Fresh Linux Server Setup

You’ve just provisioned a brand new Dedicated Linux VPS, logged in via SSH as root, created a new user, and then switched to that user — only to be hit with:

$ sudo apt update
sudo: command not found

This is one of the most common stumbling blocks on freshly provisioned minimal Linux installations. Unlike desktop Linux distributions, minimal server images (used by VPS providers for efficiency) often do not include sudo by default.

Why Does This Happen?

Minimal Linux images — the base OS templates used when you provision a VPS — are stripped of non-essential packages to keep the image as small and fast as possible. sudo is not considered essential for a root-only server, so it is frequently omitted.

Additionally, even when sudo IS installed, a newly created user will not have sudo privileges unless they are explicitly added to the sudo group (on Debian/Ubuntu) or the wheel group (on CentOS/RHEL).

Step 1: Install sudo (as root)

Since your new user cannot use sudo yet, you must first log in or switch to the root user to install it.

# Switch to root from your current user
su -

Enter the root password when prompted.

On Ubuntu / Debian:

apt update && apt install -y sudo

On CentOS / RHEL / AlmaLinux / Rocky Linux:

dnf install -y sudo
# OR for older systems:
yum install -y sudo

Step 2: Add Your User to the sudo / wheel Group

Now that sudo is installed, you need to grant your user the ability to use it.

On Ubuntu / Debian (the group is called sudo):

usermod -aG sudo your_username

On CentOS / RHEL (the group is called wheel):

usermod -aG wheel your_username

Step 3: Verify the sudoers Configuration

The sudo package comes pre-configured to allow members of the sudo or wheel group to run commands. You can verify this by checking the sudoers file using visudo (the only safe editor for this file):

visudo

Look for these lines (one of them should be present and uncommented):

# For Debian/Ubuntu:
%sudo   ALL=(ALL:ALL) ALL

# For CentOS/RHEL:
%wheel  ALL=(ALL) ALL

If the line is commented out (starts with #), remove the # to enable it.

Step 4: Apply the Group Change

Group membership changes require the user to log out and log back in to take effect. The usermod command modifies the next session, not the current one.

# Log out of the current user session
exit
# Then SSH back in as your_username
ssh your_username@your_server_ip
# Now test sudo
sudo whoami
# Should output: root

Fixing PATH Issues (sudo: command not found for specific tools)

A slightly different variant of this error occurs when sudo itself is installed and working, but a specific command like npm, pip3, or a custom script is not found when run with sudo.

This happens because sudo uses a restricted, secure PATH that does not include directories like /usr/local/bin where tools like npm are installed.

Quick fix: Use the full path to the binary:

sudo /usr/local/bin/npm install -g pm2

Permanent fix: Add the secure_path directive in /etc/sudoers via visudo:

Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

For related SSH access issues on your server, also see our guide on fixing Linux Disk Space Error 28 which can sometimes prevent SSH logins entirely, or our guide on fixing Docker bind address errors for containerized environments.

Conclusion

The sudo: command not found error on a fresh VPS is almost always caused by a missing package or an unconfigured sudoers group. By installing sudo as root, adding your user to the appropriate group, and re-logging in, you can have a fully functional, secure sudo environment in under two minutes.

Enjoy clean Ubuntu and AlmaLinux OS templates with full sudo privileges on Nextgen’s domestic VPS.