Encountering the “sudo: command not found” error can be frustrating, especially when you’re trying to perform administrative tasks on a Linux server. This error indicates that the system is unable to locate the sudo command, which is essential for executing commands with superuser privileges. Fortunately, there are several troubleshooting steps and solutions to resolve this issue and regain access to sudo functionality. The error looks like this:
1 2 3 | $ sudo apt install mariadb -bash: sudo: command not found |
Also Read: What is Superuser (Root Account) in Unix & Linux
sudo (su “do”) is a command on Unix and Unix-like operating systems such as Linux or macOS that is used to start processes with the privileges of another user (e.g. the superuser root). In contrast to su, which does not belong to sudo, it is possible to configure which commands may be executed. sudo itself a program, with its own official website which troubleshoots various complex errors:
---
1 | https://www.sudo.ws/docs/troubleshooting/ |
Usually, the sudo package by default is installed in most Linux distributions, but some Debian systems may not have it pre-installed. Usually, the sudo: command not found error is not a serious issue.
Understanding sudo: command not found Error
Before delving into the solutions, it’s essential to understand why the “sudo: command not found” error occurs. The sudo command is typically located in the /usr/bin directory, which is included in the system’s PATH environment variable. When you enter a command prefixed with sudo, the system searches the directories listed in the PATH variable to find the sudo executable. If it fails to locate sudo in any of these directories, it returns the “command not found” error.
To fix this error, logging into the system as the root user is required. You can also switch to the root user, which uncannily involves the sudo command:
1 | sudo su - |
Of course, if my username is abhishek and I am not in the sudoers group, then I may face this error. So, I need to add my username to the group.
1 | usermod -aG sudo abhishek |
Make sure your sudoers file has a sudo group added. Run visudo to modify the sudoers file and add the following line into it (if it is missing):
1 2 | # Allow members of group sudo to execute any command %sudo ALL=(ALL:ALL) ALL |
If the sudo program is not at all installed, naturally it will throw the error. Ensure that sudo is installed on your system. You can do this by running the following command:
1 | which sudo |
If sudo is installed, the command will return the path to the sudo executable (e.g., /usr/bin/sudo). If sudo is not installed, you’ll need to install it using your package manager (e.g., apt-get, yum), for example:
1 | apt update && apt install sudo |
Next if still not fixed, we should check the PATH. Verify that the PATH environment variable is correctly configured and includes the directory where sudo is located (/usr/bin). You can check the PATH variable by running the following command:
1 | echo $PATH |
The above situations are common clauses of getting the error. There are other clauses too. The sudo command should have the correct permissions (typically executable by root) to be executed. You can check the permissions using the ls command:
1 | ls -l /usr/bin/sudo |

If the permissions are incorrect, you can use the chmod command to adjust them:
1 | sudo chmod 755 /usr/bin/sudo |
If sudo is installed but still not found, try reinstalling it using your package manager. This can help fix any corrupted installation or missing files:
1 2 | sudo apt-get install --reinstall sudo (for Debian-based systems) sudo yum reinstall sudo (for Red Hat-based systems) |
If the PATH variable has been modified or corrupted, you can restore it to its default value. You can find the default PATH variable for your system in the /etc/environment file and update it accordingly. You added it to the root’s ~/.bashrc:
1 | PATH=$PATH:/usr/sbin |
and reload the file with reload command.
So, the “sudo: command not found” error can occur due to various reasons, including misconfigured PATH variable, missing sudo installation, or incorrect file permissions. Usually, it is a small issue. Remember to exercise caution when making changes to system files and configurations, especially when dealing with administrative privileges.
Tagged With chemical1gr