Most of the Linux distributions provides the
sudo command in order to run different tools and commands with root privileges. A regular user can run tools and commands with root privileges by using the sudo but the user should be configured to access sudo command. In some cases, the user can get the
sudo command not found error that prevents executing commands with root privilege.
“sudo command not found” Error
There are different cases when the “sudo command not found” error occurs. The sudo command can be used with commands like apt,useradd,mkdir,ls etc.
$ sudo useradd ali
-bash: sudo: command not found
Install sudo Command
Some distributions do not install the
sudo command by default and so it can not be executed. In order to use sudo command, we should install it properly.
Ubuntu, Debian, and Mint:
$ apt install sudo
Fedora, CentOS and RHEL:
$ dnf install sudo
Add User to Sudoers File
As sudo provides root privileges to the regular users it should be configured properly. The
sudoers file is used to configure sudo command for regular users for different commands. The username should be defined in the sudoers file in order to run sudo command. If the username is not defined he/she can not execute the sudo command. The user can be added to the sudo user group like below. The following command should be executed as root.
$ usermod -aG sudo ismail
Run Command As Root with su Command
If there is no way or installing and run the sudo command the
su command can be used to log in as
root user. Even it is not the same as the sudo command it is an alternative solution for the “sudo command not found” error.
$ su -