How to Fix the “sudo: command not found” Error on Linux

Configurare noua (How To)

Situatie

Sometimes, when you try to run a command as the root user using sudo, you receive a “command not found” error.

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.

Solutie

Pasi de urmat

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.

Tip solutie

Permanent

Voteaza

(4 din 9 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?