Introduction
If you are a Linux user, you may have encountered the error message “-bash: sudo: command not found” when trying to run a command with sudo. This error occurs when the sudo command is not installed or is not in the user’s PATH. In this article, we will discuss how to fix this error and get the sudo command working again. We will cover how to install sudo, how to add it to the PATH, and how to troubleshoot any other issues that may be causing the error.
How to Fix “-bash: sudo: command not found” in Linux
1. Check if sudo is installed:
Run the following command to check if sudo is installed on your system:
which sudo
If the output is something like “/usr/bin/sudo”, then sudo is installed.
2. Check if sudo is enabled:
Run the following command to check if sudo is enabled on your system:
sudo -l
If the output is something like “User
3. Check if sudo is configured correctly:
Run the following command to check if sudo is configured correctly on your system:
visudo
If the output is something like “Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin”, then sudo is configured correctly.
4. Reinstall sudo:
If sudo is not installed, or if it is not enabled or configured correctly, you can reinstall it using your Linux distribution’s package manager. For example, on Ubuntu, you can run the following command to reinstall sudo:
sudo apt-get install sudo
Once sudo is reinstalled, you should be able to use it without any issues.
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
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
From here, you can comfortably run commands using sudo without an issue at all.
# su tecmint $ whoami $ sudo apt install apache2
In this guide, we have demonstrated how to resolve the “sudo command not found” error in Linux. Your comments and feedback are welcome.
If You Appreciate What We Do Here On Jassweb, You Should Consider:
Jassweb is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit Jassweb! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
How to Fix “-bash: sudo: command not found” in Linux
If you are a Linux user, you may have encountered the “-bash: sudo: command not found” error. This error occurs when the sudo command is not found in the system. The sudo command is used to run commands as the root user or another user. It is an important command for system administrators and users who need to perform administrative tasks.
The “-bash: sudo: command not found” error can be caused by several different issues. In this article, we will discuss how to fix this error and get the sudo command working again.
Check if sudo is Installed
The first step is to check if sudo is installed on your system. To do this, open a terminal window and type the following command:
which sudo
If sudo is installed, the output of this command will be the path to the sudo binary. If sudo is not installed, the output will be nothing.
Install sudo
If sudo is not installed, you can install it using your Linux distribution’s package manager. For example, on Ubuntu and Debian, you can use the apt command to install sudo:
sudo apt install sudo
On CentOS and Fedora, you can use the yum command to install sudo:
sudo yum install sudo
Check sudo Configuration
If sudo is installed, you should check the sudo configuration to make sure it is configured correctly. To do this, open the sudoers file in a text editor:
sudo nano /etc/sudoers
The sudoers file contains the configuration for sudo. Make sure that the user you are trying to run sudo as is listed in the file. If the user is not listed, you can add it by adding a line like this:
username ALL=(ALL) ALL
Replace “username” with the username of the user you want to be able to use sudo.
Conclusion
In this article, we discussed how to fix the “-bash: sudo: command not found” error in Linux. We discussed how to check if sudo is installed, how to install it, and how to check the sudo configuration. If you follow these steps, you should be able to get the sudo command working again.