-bash: sudo: command not found Error and Solution

I‘m typing the following command:

But, getting the error:

How do I fix this problem under Debian / Ubuntu / RHEL / CentOS Linux?

This error means the sudo command is not installed. The sudo command allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file.

Step #1: Become a root user

Use su – command as follows:
$ su -
When prompted you need to type the root user’s password.

Step #2: Install sudo tool under Linux

If you are using Debian or Ubuntu Linux, enter:
# apt-get install sudo
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 610 kB of archives.
After this operation, 983 kB of additional disk space will be used.
Get:1 http://security.debian.org/ squeeze/updates/main sudo amd64 1.7.4p4-2.squeeze.3 [610 kB]
Fetched 610 kB in 4s (132 kB/s)
Selecting previously deselected package sudo.
(Reading database ... 30838 files and directories currently installed.)
Unpacking sudo (from .../sudo_1.7.4p4-2.squeeze.3_amd64.deb) ...
Processing triggers for man-db ...
Setting up sudo (1.7.4p4-2.squeeze.3) ...
No /etc/sudoers found... creating one for you.

If you are using RHEL / CentOS / Fedora / Scientific Linux, enter:
# yum install sudo
Sample outputs:

Loaded plugins: product-id, protectbase, rhnplugin, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
0 packages excluded due to repository protections
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package sudo.x86_64 0:1.7.4p5-12.el6_3 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package        Arch             Version                       Repository                      Size
 sudo           x86_64           1.7.4p5-12.el6_3              rhel-x86_64-server-6           423 k

Transaction Summary
Install       1 Package(s)

Total download size: 423 k
Installed size: 0  
Is this ok [y/N]: y
Downloading Packages:
sudo-1.7.4p5-12.el6_3.x86_64.rpm                                             | 423 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : sudo-1.7.4p5-12.el6_3.x86_64                                                     1/1 
Installed products updated.
  Verifying  : sudo-1.7.4p5-12.el6_3.x86_64                                                     1/1 

  sudo.x86_64 0:1.7.4p5-12.el6_3                                                                    


Step #3: Add admin user to /etc/sudoers

You need to add yourself to /etc/sudoers file, enter:
# visudo
Grant vivek user full permission via sudo:

vivek   ALL=(ALL) ALL

Save and close the file.

How do I use sudo?

To become a root user and start root shell, enter:
$ sudo -i
$ sudo -s
To run a command called ‘/sbin/service httpd restart’, enter:
$ sudo /sbin/service httpd restart
To reload squid proxy server, enter:
$ sudo /usr/sbin/squid3 -k reconfigure
Sample outputs:

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
[sudo] password for vivek:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Marko Nov 13, 2014 @ 17:18

    Thanks for this! I’m learning Linux (using Fedora) and I managed to remove sudo when I removed vim-minimal.

  • med Apr 20, 2016 @ 2:46

    i have “passwrd: command not found” in ideneb 1.3 , when i type “passwrd root” to config setup….do u have an idea.
    thank u!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum