Resolving the “sudo: command not found” Error in Linux

Published January 28, 2024

Resolving the “sudo: command not found” Error in Linux.

Linux

Explain More ; Unlocking AnLinux: Your Guide to Installation and Seamless Usage

How to Fix sudo: command not found Error in Linux?

To address the “sudo: command not found” error on Linux, simply install the sudo package using the command apt install sudo if you’re using a Debian-based distribution. This bash error occurs when the sudo package is not installed or when the PATH variable doesn’t include the directory where sudo is located. By installing sudo, you ensure the availability of the sudo command, granting administrative privileges and resolving the issue.

2 Methods to Fix bash: sudo: command not found error

1. Install sudo Command in Linux

To execute a command with root or another user’s privileges, utilize the sudo command. While sudo is typically pre-installed on most systems, certain Linux distributions like Debian 10 and later, RHEL 8 and later, CentOS, Fedora, and Arch Linux might lack it. To install the sudo package, log out of your user account and log in as root. Execute the following command:

$ sudo su –

Switch to the root user, update the package lists, and install the sudo package by executing the following command:

# apt update -y # apt install sudo -y

Switch to the root user on Debian-based systems and install sudo by executing the following command:

su – apt install sudo

To install sudo on CentOS StreamFedoraRocky Linux, or Alma Linux, enter:

# su – # yum install sudo

To install sudo on Arch Linux, type:

# pacman -Sy sudo

To give all the sudo permissions, run:

$ user od -AG <username>

Then, you can check the permissions by opening the ‘sudoers’ file:

$ nano /etc/sudoers

Now, you should be able to use sudo to execute all the commands.

2. Add sudo’s Directory to PATH Variable

In Linux, the PATH variable, an environment variable, maintains a list of paths to locate executable files for the commands you execute. The “bash sudo command not found” error may arise when the PATH Variable cannot locate the directory where sudo is situated.

Verify your PATH by running the echo command:

echo $PATH

If sudo’s directory is in your PATH, You will get one of the following directories in output:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

If sudo’s directory is not in your PATH, you can add /usr/bin directory by following command:

export PATH=$PATH:/usr/bin

By running this command, the path variable can find the directory containing sudo. So bash error in Linux will be solved.

Add User to Sudo Group in Linux [CLI & GUI Methods]

Once you’ve installed the sudo package and resolved the sudo command not found error in Linux, you can add users to the sudo group using both the command line and graphical user interface (GUI).

1. Using Command-Line

To add a Superuser on Ubuntu and Debian, run:

sudo adduser username

Run the following command to add your user to the sudo group on Debian:

usermod -aG sudo your_username

Then, you can confirm whether the user has been added to the group by issuing the following command:

# groups your_username

Replace the name of the user you need to check that has been added to the group with your-username in the above command.

To add the user to the wheel group on Arch-based systems, type:

usermod -aG wheel your_username

And use the command below to add your users to the sudo group on Fedora and other RHEL-based distros:

usermod -aG wheel your_username

By the way, you can use a single command instead of multiple commands to create a new superuser:

sudo adduser username sudo

The verification procedure is unchanged from before.

To test if the bash error has gone, log back in as your regular user. If all have passed successfully, you should not view sudo: command not found error anymore, and fixing must have been finished at this point.

2. Using Graphical Interface

Create a new user through the command line, and then follow these steps to add the user to the sudo group using the GUI method.

Step 1. To view a list of users and find the newly created user/users, go to the Application menu and click on the Users option.

Clicking on the Unlock option and entering the root password allows you to switch to another user account.

Step 2. As soon as you choose it, an option to make the newly created user account an administrator account will appear. To add the account as a sudo account, toggle the button next to the Administrator label.

There, you added a sudo user using the graphical interface.

Explore More; Exploring Android Terminal Emulators on Linux

Stay Connected with us on Meta, X, Instagram .