command not found" Error on Linux

Publish date: 2024-03-24

When setting up a new Linux desktop or virtual machine, you may encounter the "sudo: command not found" error. This Linux error message can be infuriating and prevents you from progressing further with your setup. Here's what it means and how to fix it.

What Is "sudo" in Linux?

User accounts on Linux come with a limited set of privileges that prevent them from performing administrative tasks which may damage the system. These limited privileges keep users from accessing certain areas of the filesystem or from executing certain files.

The one user who has no such restrictions on their actions is the root user. The root user can access any area of a Linux system, and execute any command on any file.

Because of this immense power, you should disable the root account and use sudo instead.

The sudo command is short for "superuser do" and allows a user who is part of the sudo group to execute a command as if they were the root user. It effectively gives them root powers and permissions—as long as they use sudo and authenticate with a password.

Why Is the sudo Command Not Found?

Apart from being a useful command, sudo is also a package. On most systems, sudo is installed by default. But this is not the case on all distros, and when you attempt to run a command using sudo on such distros, you may receive the error, "sudo: command not found".

This is common on newly installed Linux systems. This can be especially frustrating if you spent hours installing and setting up Linux, only to log into your user account and discover the Bash sudo command not found error.

When you run into sudo not found errors, the first thing you might try to do is install the sudo package with a package manager like APT, Pacman, or DNF:

sudo apt install sudo 

This will fail because as you are already experiencing the sudo command not found error, you can't use sudo to install packages as the root user.

How to Fix "sudo: command not found" on Linux

As your user cannot assume the privileges of the root user without already having sudo installed, you need to log out of your user account and log in as root.

As the root user, you can install the sudo package with the privileges this account possesses, so it's not subject to the Linux "sudo command not found" error.

On Debian-based systems, enter:

apt install sudo 

Then, add your user to the sudo group using:

usermod -aG sudo your_username 

On Arch-based systems, enter:

pacman -S sudo 

Then, run the following to add the user to the wheel group:

usermod -aG wheel your_username 

On Fedora and other RHEL-based distros, install sudo with:

dnf install sudo 

Then, add your user to the sudo group by issuing the following command:

usermod -aG wheel your_username 

When you log back in as your regular user, you'll discover that the "sudo: command not found" error is a thing of the past.

If you continue to see "sudo: command not found" errors on Debian or Ubuntu, you should consider reinstalling your distro or even try a different Linux distro altogether.

You Can Now Run Commands With sudo on Linux!

You have successfully installed sudo and added your user to the sudo group, meaning that you can run any command and access any area without needing to log in as root.

While sudo substantially improves the security of your Linux machine, you should use this power carefully, as elevated privileges can be dangerous, especially in production environments.

ncG1vNJzZmivp6x7rq3KnqysnZ%2Bbe6S7zGidorBdqMKlu4ycpqalkaOxbrrOrWSfp6WjsW67zWajoqalrXw%3D