How to Fix “-bash: sudo: command not found” in Linux

Have you ever tried to run a Linux command using sudo only to see the warning “sudo command not found” splashed on your terminal? This can be quite frustrating and it prevents you from working on your system as a non-root user while performing administrative tasks.

In this guide, we look at how to fix the “sudo command not found” error in Linux.

$ sudo apt install apache2

-bash: sudo: command not found

What Is Sudo Command in Linux?

Sudo, an abbreviation for superuser do, is a program that allows users to run commands or programs with root or elevated privileges. Usually, using sudo is the recommended way to run a Linux system instead of using the root user. This mitigates the risk of breaking the system in case a potentially dangerous command is executed.

The sudo package ships by default in most Linux distributions, and you should not have a problem using it. However, this does not always apply to all Linux distributions. There are particular cases where the system does not come with sudo installed. This is especially true for older Debian systems such as Debian 10 and later.

The “sudo command not found” error is nothing to be worried about and in case you have encountered this error, worry not. You can address it in a few simple steps.

How to Fix “sudo command not found” in Linux

To fix this error, log into your system as the root user or simply switch to the root user.

$ sudo su -

Next, update the package lists and install the sudo package as follows.

# apt update -y
# apt install sudo -y
Install Sudo in Debian-based Systems
Install Sudo in Debian-based Systems

If you are running an RHEL-based distribution such as CentOS Stream, Fedora or Rocky/Alma Linux switch to the root user.

# su -

Then install sudo using the yum command as shown.

# yum install sudo

For Arch Linux, run the command.

# pacman -Sy sudo

Add User to Sudo Group in Linux

From here, you can add users to the sudo group. For example, to add user tecmint to the sudo group, run the command.

# usermod -aG sudo tecmint

To confirm that the user has been added to the group, run:

# groups tecmint
Add User to Sudo Group
Add User to Sudo Group

From here, you can comfortably run commands using sudo without an issue at all.

# su tecmint
$ whoami
$ sudo apt install apache2
Run Sudo Command in Linux
Run Sudo Command in Linux

In this guide, we have demonstrated how to resolve the “sudo command not found” error in Linux. Your comments and feedback are welcome.

Winnie Ondara
My name is Winnie, a Linux enthusiast and passionate tech writer in Linux and DevOPs topics. I enjoy keeping abreast with the latest technologies in the Linux ecosystem and trying out new tools provided by the FOSS community.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

3 Comments

Leave a Reply
  1. Simply switch to the root user.

    $ sudo su -
    

    If you are getting the “sudo command not found” error, this will not work.

    Reply

Leave a Reply to ThumbOne Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.