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.

Two small things before you go

If something didn’t work on your setup, leave a comment and tell me which distro and version you’re on. I read every one, and most of these articles got better because a reader pointed out what was missing.

And if it did work, share it. TecMint has stayed free for 14 years because people pass these articles around, and that traffic is what pays for writing the next one.

Leave a comment
Get two free Linux courses

Learn the Linux basics with two free courses and join 34,000+ readers getting practical TecMint tutorials and selected Pro TecMint articles every week.

Pro TecMint
Get lifetime access for $99

If you want to go beyond the free tutorials, Pro gives you 18 courses, 5 ebooks, and every future course I add. One payment, lifetime access, no renewals.

Winnie Ondara
Winnie Ondara
Contributor
About the author

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.

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

Got Something to Say? Join the Discussion...

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.