Ошибка bash sudo command not found

There are many scenarios when you get “sudo command not found error” and you keep looking for solutions on the internet to fix it. One of the common examples, when you have installed Debian with a minimal package and trying to run sudo. For me whenever I try to ssh into any of the remote servers and run sudo, I get this “bash: sudo commands not found error”. So I decided to write a post, which covers all the scenarios of this famous error.

Below mentioned errors will be covered in this post. so if you are getting any of the following errors, this post will definitely solve your error –

  • sudo command not found mac
  • sudo command not found ubuntu
  • sudo command not found debian
  • zsh sudo command not found
  • sudo command not found windows
  • sudo command not found centos
  • bash: /usr/bin/sudo: No such file or directory

These are the common scenarios that result in this error –

  • You have installed a linux distribution with minimal package like Debian
  • Sudo is not installed
  • Path is not setup for sudo command
  • You are trying to ssh a remote server first time and sudo is not working

Before getting into the solutions, if you are a newbie let’s understand why sudo is used?

Why sudo is used in Linux before every command?

Sudo is one of the famous prefixes to any command you run in the Linux world. It allows running any Linux command with elevated privileges to run administrative tasks. Also, the operations which are only permitted by a root user can be done using a normal user with sudo rights. The “sudoersfile controls, who can use the sudo command to gain elevated access and location is /etc/sudoers in all Linux distributions.

How to fix sudo command not found error in Debian/Ubuntu like Distros

As we discussed already, there may be many reasons to encounter this error. As you will see in the image, running the “sudo ifconfig -a” command results in “bash: /usr/bin/sudo: No such file or directory error“. I am running this command in Ubuntu 21.04 installed as VM.

bash sudo command not found error in Ubuntu

Let’s deep dive and find the fixes for different scenarios –

Solution-1 Check and install sudo package

This is very uncommon when sudo is not installed by default with Linux installation. Still, you may get this situation when you have installed the Debian Linux with the minimal package. Follow these steps to fix it –

Step1.1 List installed packages in Ubuntu and look for the “sudo” package

$ apt list --installed | grep -i sudo

check installed packaged list for sudo

If you can find package name sudo with “installed” status as shown in the image. Then you can directly move to solution-2 to fix the “sudo: command not found error“.

If you don’t have the sudo package installed, run the following command to install it in Ubuntu or Debian based distros. You would need root access to achieve this.

Step1.2 Switch to root user

$ su root

Enter “root” password, when prompted.

If you don’t have a root password, then follow this link to reset your root password.

Step1.3 Run apt command to install sudo package in Ubuntu/Debian

# apt install sudo

Refer to the following image for reference.

install sudo to fix sudo command not found in ubuntu

Step1.4 Give sudo rights to your own user by adding it to the sudo group

# usermod -aG sudo yourusername

For example, I will add my user “dev” to sudo group –

# usermode -aG sudo dev

add user to sudo group

Step1.5 Verify your user is added to the sudo group

Open /etc/passwd file and check whether your user is added to the sudo group or not.

# cat /etc/group | grep -i username

I will check for my user “dev” in this example.

 # more /etc/group | grep -i username 

check user has been added to sudo group

Step1.6 Make sure your sudoers file have sudo group added

  • Run visudo command to modify sudoers file and add the following line into it (if it is missing):
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

Enable sudo group to execute any command in sudoers file

Press Ctrl + X and press “Y” to save the file and exit from the nano editor.

Exit from the root shell and check the sudo command functionality.

  • Run sudo -h command. Now you will not get any “sudo command not found error” as it’s fixed now.

sudo commands help

Solution2 – Setup path variable to fix sudo command not found errors

If you have a sudo package installed as explained in Step 1.1 and still you are getting sudo command not found error. It means you don’t have “/usr/bin/” setup in the PATH variable or your /etc/environment file got messed up.

To add sudo in your Path variable, add /usr/bin/ directory by following the method.

Step2.1 Switch to root user

$ su root

Enter root user password, when asked.

Step2.2 Run /usr/bin/sudo command to check whether it’s working or not

# /usr/bin/sudo -h

Step2.3 Edit /etc/environment file and add “/usr/bin" directory in PATH

# vi /etc/environment

Add path variable to fix sudo command not found Debian

Alternatively, you can also run export command to set up the path variable

export PATH=$PATH:/usr/bin

In case you are getting visudo and usermod command not found errors also. Make sure you add /usr/sbin in the PATH variable as shown in the last step.

Fix “sudo command not found error” in Fedora/AlmaLinux/Rocky Linux Distros

This section covers sudo error for all the Linux distros based on RedHat like Fedora, AlmaLinux, CentOS and Rocky Linux. I have Rocky Linux Installed as a virtual machine. The procedure is the same as explained earlier, Look for the package, install it and set the path variable, if required. But the commands will differ now.

Solution3- Install sudo and add user to “Wheel” group to fix sudo errors

You have the option to set up sudo during installation in RedHat based Linux distros. But if you forgot to do that, You must have access to the root user to set up sudo for your user.

Step3.1 – Login with root user and check for sudo package installation

Follow this link to reset your root password, in case you forgot or don’t have it.

Once you are done with login as root, open Terminal and type

# yum list installed | grep -i sudo

If you get the sudo package installed already skip to the next step3.3.

Step3.2 Install sudo package

You can use the “yum” or “dnf” command to install any package from the repository.

Update all old packages and refresh the repository.

# dnf update 

Then install the sudo package using the dnf or yum command.

# yum install sudo

or
 
# dnf install sudo

Install sudo to fix sudo command not found in Centos or Rocky Linux

Step3.3 Add user to the wheel group

The wheel group is already set to provide sudo access to run all commands. So is the quickest way is to add your user to this group. Switch to the root user first using su command

su -

Now run usermod command to add your user in the wheel group.

# usermod -a -G wheel "username"

For example, I will add my user “dev” as an example

 # usermod -a -G wheel "dev" 

Add user to wheel group to fix zsh sudo command not found error in Fedora

Step4.4 Check with the id command

Next, run the id command to see whether your user is part of the wheel group or not.

# id "username" 

Example: My user dev is part of 10(wheel) the group.

# id dev

check Id has been added to wheel group

Congrats! you must have fixed your “sudo command not found error ” now and you can run all your privileged commands using sudo.

Frequently asked questions on sudo

Q1: Why is sudo not working?

These are many reasons when sudo may not work –

1. You don’t have a sudo package installed
2. If the sudo package is installed then the path variable is not set up correctly
3. Your system got broken and all your packages and permissions got messed up
4. Your user is not added to the sudo or wheel group based on your Linux distro.

Q2: How do I enable sudo?

If the sudo package is already installed based on your Linux distro run the following command. Replace “dev” with your username.

for Ubuntu and Debian based distros –

$ su root

Then run the usermod command to add your user to the sudo group

# usermode -aG sudo dev

For RedHat based distros –

Switch to root (superuser)

$ su -

Add to the wheel group.

# usermod -a -G wheel dev

Q3: How do I find sudo commands?

Open terminal and type sudo -h. It will show you all the sudo command options and arguments. You can also type man sudo to get the manual of the sudo command.

Q4: How do I fix sudo command not found Mac?

Run the following sequence of commands to fix the sudo command not found error in macOS.

1. Check the syntax of command and spelling of sudo, so that you are sure, you are not running the misspelt command

2. switch to root user
$ su -

3. Run the following command

In the case of OS prior to Catalina

# visudo /etc/sudoers

in the case of Catalina

# visudo /private/etc/sudoers

4. Add your user as follows in sudoers file –

username ALL=(ALL) ALL

replace username with your user. e.g John

Save and exit sudoers file

5. reopen the terminal and it will fix all your zsh: sudo command not found error in macOS.

Q5: Do I need to install sudo?

By default all the Linux or Unix distros have sudo installed. But in case you don’t, then you must install sudo. it is the recommended way to use root privileged commands (only when required) and helps to avoid mistakes that can break your system.

Ending Note

I have covered all the possible solutions to fix the sudo command not found error and I hope this tutorial is helpful to you. In case, none of the solutions works for you and your system has broken severly, Either re-install your system or let me know the issue via your comments.

I will try to help you to the best of my knowledge.

Keep Learning!!

Sudo is a program that let users run programs with the security privileges of another user. To run administrative applications in Linux, users can take advantage of sudo. In this article, you will learn How to fix sudo command not found, to be able to continue using its benefits since users usually face the error ‘’command not found’’ even if they have the command installed.

After buying Linux VPS, you will start installing programs, running a Linux command, or setting up a new Linux desktop. All of these actions must be done using Sudo. So, it is inevitable to be mastered to fix sudo command not found error.

An Intro to Linux Sudo Command

The sudo command, which stands for “superuser do,” is a command-line utility that enables a user of the sudo group to issue commands in the same way as the root user. As long as they utilize sudo and password-authenticate, it basically grants them root privileges. Only superusers are permitted to run the sudo commands, and it is typically used as a prefix for numerous other Linux commands. This command is comparable to Windows’ “Run as Administrator” option. A log of all commands and arguments is also kept by sudo.

There are several user accounts on the Linux system. To prevent user accounts damage the Linux system while performing administrative tasks and not being able to access sensitive areas of the filesystem and run certain files, they come with limited privileges. The root user is not included with mentioned restrictions and is able to do any actions on the Linux system and also access all certain areas and run any sensitive commands. Obviously, the root account must be disabled. In this situation, the Sudo is used instead.

Using sudo instead of the root user is advised while operating a Linux system. This reduces the chance that potentially dangerous commands in linux may cause the system to crash. Most Linux distributions include the sudo package by default, so using it shouldn’t be a problem.

The ”sudo not found” error is not a big deal and using this guide you can easily learn how to fix the errors like -bash: sudo command not found or fix sudo command not found.

Why ”sudo command not found” occur?

In Linux and UNIX-like systems, the Sudo command executes a specific command with root privileges. This does not necessarily hold true for all Linux distributions, though. There are some situations where sudo may get removed or not pre-installed on the system such as Debian 10 and later, and it causes receiving the error message ”sudo: command not found.”

How sudo command not found occure

When working on a Linux system, especially on a newly installed Linux system, it is not that unusual to get the Bash sudo command not found error. If you faced this error while installing and setting up your Linux server, do not get disappointed and just follow the simple steps of this guide to learn the best way you can fix sudo command not found and get rid of receiving this frustrating error and proceeding further with the setup process.

As you guess, the solution to solve the sudo: command not found error is to install it on your Linux server. In the following of this tutorial, you will learn how to do this easily.

Easiest Technique to Fix Sudo Command Not Found Error

Let’s go through this tutorial and find the simple solution to fix sudo command not found, once forever. You must log out of your user account and log in as root because your user cannot take on the rights of the root user unless sudo is already installed. You can install the sudo package as the root user using the permissions that this account has.

To log into your system, run the command below as the root user:

$ sudo su -

You can also switch to the root user. Now, you can update the package lists and install the sudo package. So, simply run:

# apt update -y
# apt install sudo -y

To install sudo on CentOS Stream, Fedora, Rocky Linux, or Alma Linux, use the following command to switch to the root user and then, install sudo:

# su -
# yum install sudo

To install sudo on Arch Linux, type:

# pacman -Sy sudo

On Debian-based systems, enter:

apt install sudo

To give all the sudo permissions, run:

$ user od -AG <username>

Then, you can check the permissions by opening the ‘sudoers’ file:

$ nano /etc/sudoers

Now, you should be able to use sudo to execute all the commands.

Add User to Sudo Group in Linux [CLI & GUI Methods]

Once you solve the sudo: command not found error, you can add users to the sudo group. Find and use the related command of your running distribution. If you prefer to use the graphical interface to add user to sudo, skip the first method to the second one.

1. Using Command-Line

Launch the terminal and run the following command to add a Superuser on Ubuntu and Debian:

sudo adduser username

Run the following command to add your user to the sudo group on Debian:

usermod -aG sudo your_username

Then, you can confirm whether the user has been added to the group by issuing the following command:

# groups your_username

Replace the name of the user you need to check that has been added to the group with your-username in the above command.

To add the user to the wheel group on Arch-based systems, type:

usermod -aG wheel your_username

And use the command below to add your users to the sudo group on Fedora and other RHEL-based distros:

usermod -aG wheel your_username

By the way, you can use a single command instead of multiple commands to create a new superuser:

sudo adduser username sudo

The verification procedure is unchanged from before.

To test if the error has gone, log back in as your regular user. If all have passed successfully, you should not view the ‘’sudo: command not found’’ error anymore, and fixing sudo: command not found must have been finished at this point.

2. Using Graphical Interface

To use the GUI method to add the user to the sudo, you must first create a new user through the command line and then, follow the below steps to proceed.

Step 1. To view a list of users and find the newly created user/users, go to the Application menu and click on the Users option.

Add user using GUI

Step 2. Here you can switch to another user account if you click on the Unlock option and on the root password.

How to Add user via GUI

As soon as you choose it, an option to make the newly created user account an administrator account will appear. To add the account as a sudo account, toggle the button next to the Administrator label.

There, you added a sudo user using the graphical interface.

What to Do After Fixing sudo: command not found in Linux?

According to your running distribution, you can choose the related commands explained in this guide to fix sudo command not found. When everything finished successfully, you can run any command and access any place without having to log in as root because you successfully installed sudo and added your user to the sudo group. Although sudo significantly increases the security of your Linux machine, you should exercise caution when using this power because elevated privileges can be risky, especially in production environments.

FAQ

On Linus systems, sudo is a package that is pre-installed. However, sudo is not installed on some Linux editions, and when you run the command on one of these systems, you get the error «sudo: command not found.»

No. Su and sudo both increase the current user’s privileges. The primary distinction between the two commands is that su calls for the target account’s password, whereas sudo calls for the current user’s password. Therefore, using sudo is significantly safer because it avoids sending sensitive information.

When sudo run commands with a fresh environment instead of inheriting modified environment variables, the ‘’command not found’’ error will be displayed.

Conclusion

In this article, you learned about sudo: command not found error, the reason for occurring, and the way you can fix it. Obviously, due to security reasons, in Linux systems only the root user and users who have been granted administrative task rights by the root user are given permissions. As you reviewed, this error is not that complicated contrary to its appearance. You just need to go into the root user mode and install the sudo tool using the existing commands in this article. We tried to offer the best and simplest solution to help you fix sudo command not found and continue performing commands on your Linux system.

If you follow the above steps properly then you can smoothly fix the error, but do not hesitate to contact us if you encounter any problems. Our technical support team will try their best to solve your problems.

Если в ОС Debian или Ubuntu вы захотели выполнить любую команду с sudo и получили ошибку

-bash: sudo: command not found

То скорее всего у вас просто не установлен sudo

Чтобы исправить эту проблему заходим под суперпользователем, для этого вводим команду

su

вводим пароль от рута (root)

И уже с root-правами выполняем команду

apt-get install sudo

После этого все должно заработать

ВАЖНО:  Чтобы текущий пользователь мог выполнять команды с правами суперпользователя используя sudo — он должен состоять в соответствующей группе,

Чтобы добавить пользователя в группу sudo, выполните команду

usermod -a -G sudo user

где user — имя вашего пользователя

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.

If you read this far, tweet to the author to show them you care. Tweet a thanks

Photo of 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.


Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Before discussing how to fix sudo commands not found in Debian we will first discuss what Sudo is. Sudo means the superuser; as a superuser you have all the privileges which a root user can enjoy. Different distributions of Linux are such as Ubuntu, Fedora, and Mageia. Similarly, Debian is also an example of Linux general distribution. Ubuntu distribution is used for beginners whereas Debian is an advanced distribution that is used on an expert level. While working on Debian sometimes we found an error using the “sudo” command. It may be something like “sudo command not found”, “[user name] is not in the sudoers list” or maybe some other error that means the same.

This write-up is associated with the solution with which we can resolve this error. We will discuss both errors separately which are related to the sudo package, when we face them and how we can resolve these issues.

By default in Debian, the sudo command is installed but sometimes it happens that we use the sudo command and it generates the following error.

We simply enter the root user mode as:

So it means that the sudo package is not installed by default so to resolve this issue we simply go to the user mode and install the package. First, we will go to the root user mode.

Update the repository first.

Install the sudo package.

Exit the root mode.

To verify the installation of the error we will again enter the root by using sudo command.

The issue which has been discussed at the start is now resolved.

How to add user to sudoers file to resolve the error

We simply run the command of the list of disks on Debian.

We have the output, “zhammad is not in the sudoers file . This incident will be reported.”, this is an error which means we cannot use the sudo command. Sudo command is an administrative command which is used with those commands which need administrative permissions. Now it means the user “zhammad” does not have the administrative rights so to access those permissions we have to install the “sudo command” manually and give the administrative privileges to this user.

We will switch the user to administrative user which is “hammad” in our case. So by using the “su command” we switch to hammad from zhammad.

Now as we switch the user to hammad, we will go to the root mode.

Update the repository of Debian by using the update command.

As we can see in the output, the repository is updated and all the packages are up to date so no need to upgrade the repository. Now we add the new user in the list of sudoers file by using the command.

# usermod -aG sudo zhammad

The user has been added to the list of sudoers and for the verification of this we used the command of “id”.

In the above output, we see the zhammad user is also added to the list of sudo. After verifying this we will exit the root mode by typing “exit”.

For switching back to the zhammad from hammad.

Again run the command of fdisk and confirm that the issue has been solved.

The command runs successfully and displays the list of disks. So our issue has been resolved.

Conclusion

Sudo is used for the commands which are making the changes in the root folder and administrative things. For a secure purpose, these permissions are only given either to the root user or the user which are allowed by the root user. We have discussed the solution of the issue in this write-up which is to resolve it by installing the sudo manually (if it is not installed so can be installed by this command else it is installed in Debian by default) and adding the user to the list of sudoers by switching to the administrative user account. I tried to assist you with the solution of “sudo command not found” in this write-up and hope this will help you in resolving the issue.

About the author

I’m an Engineering graduate and my passion for IT has brought me to Linux. Now here I’m learning and sharing my knowledge with the world.

Понравилась статья? Поделить с друзьями:
  • Ошибка basegui ppl
  • Ошибка base dcl
  • Ошибка base 1132
  • Ошибка bas на мерседес w220
  • Ошибка bas на мерседес w203 что означает