[Fixed] “bash: sudo: command not found” Error

When you are trying to install a new Linux Desktop or Virtual Machine, you might get the error “sudo: command not found”. This error stops you from performing administrative tasks on your Linux. One common cause of encountering the error is that the sudo command is not installed on the system or its installation is incomplete, and another possibility is that the directory containing the sudo executable is not included in the system’s PATH environment variable. This article is going to discuss how to fix “bash: sudo: command not found” error in your Linux distribution. So, let’s see!

What is “sudo” Command in Linux?

In Linux, the sudo command stands for “superuser do.” It is a command-line utility that enables users to execute commands with the privileges of another user, typically the superuser or root user. On Linux, regular user accounts have limited privileges to prevent them from causing harm to the system. These restrictions prevent them from accessing certain parts of the filesystem or running specific commands. However, the root user has unrestricted access to the entire Linux system, allowing them to execute any command and access any file.

To improve security and limit the risk of system damage, it’s advisable to deactivate the root account and instead utilize sudo. Sudo enables users to perform administrative tasks by temporarily assuming the privileges of the root user after verifying their identity with their passwords.

2 Ways to Fix “sudo: command not found” Error in Bash

There are two ways you can fix the “sudo: command not found” error in Bash:

1. Install “sudo” Command in Linux

To install the sudo command on a Linux system, you typically need to use your system’s package manager. However, you should first check if the “sudo” already exists in your distribution or not.

To check if the sudo command is present in your system, run the following command.:

whereis sudo

Check if the sudo command is in systemAs you can see, I already have the sudo command in my distribution. However, if it’s not installed, you need to install it.

To install the sudo command, first run the following command to switch to the root user’s environment:

sudo su -

Next, update the package lists and install the sudo command as follows:

apt update -y
apt install sudo -y

Install sudo Command in LinuxThus, the above commands will install the sudo command on your system.

Note: To install the sudo command on CentOS Stream, Fedora, Rocky Linux, and Alma Linux, use su - and then yum install sudo subsequently in the terminal. On Arch Linux, use pacman -Sy sudo.

2. Add sudo’s Directory to PATH Variable

Only installing the sudo command is not enough if it cannot locate the directory where the command resides.

To verify your system’s PATH environment variable, run the following command:

echo $PATH

If the directory containing sudo is in your PATH, one of the following directories will be displayed in the output:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Add sudo’s Directory to PATH VariableIf the sudo directory is not in your PATH, you can add the /usr/bin directory by running the following command:

export PATH=$PATH:/usr/bin

After running this command, the path variable will be used to find the directory that contains sudo. Thus, you can resolve the “sudo: command not found” error.

Conclusion

In conclusion, encountering the “bash: sudo: command not found” error can be frustrating, but resolving it is essential for maintaining the functionality and security of your system. By following the methods outlined in this article, you can quickly address the issue and ensure that sudo is properly installed and configured on your Linux system. Further, if you have any questions or concerns regarding this article, feel free to comment below. Thank you!

People Also Ask

How to install sudo on Bash?

You typically don’t need to install it separately as it’s a standard utility included with most Linux distributions. However, if sudo is not already installed, you can usually add it using your system’s package manager. For instance, on Ubuntu or Debian systems, you can update the package lists with apt install sudo -y. On CentOS or RHEL, you can install sudo using yum install sudo, while on Fedora, you would use dnf install sudo. Once sudo is installed, you may need to grant your user account permission by adding your username to the sudoers file. You can do this by running usermod -aG sudo your_username, replacing “your_username” with your actual username. Following these steps will enable you to use sudo on your Bash shell.

Why is sudo not found?

There are several potential reasons if the “sudo” command is not found on your system. Firstly, sudo may be not installed on your system. While this is uncommon as most Linux distributions come with sudo pre-installed, it can happen on minimal or custom installations. Secondly, the directory containing the sudo executable might not included in your system’s PATH environment variable, which determines where the system looks for executable files. Another possibility is that the sudo installation has become corrupted or the sudo executable has been accidentally deleted. Lastly, if your user account does not have permission to execute sudo, it may not be accessible. This can occur if the permissions on the sudo binary have been modified incorrectly.

How to install “bash” in command?

To install Bash via the command line in Ubuntu or Debianbased systems, begin by updating the package lists with sudo apt update, followed by installing Bash using sudo apt install bash. Similarly, on CentOS or Red Hat Enterprise Linux (RHEL), you can install Bash by running sudo yum install bash. If you’re using Fedora, you can achieve the same with sudo dnf install bash. These commands ensure that Bash is downloaded from the distribution’s repositories and installed onto your system. It’s important to run these commands with sudo or as the root user to have the necessary permissions for installing packages.

How do I open the Bash command in Linux?

To open the Bash command-line interface, you’ll need to launch a terminal emulator specific to your operating system. On Linux distributions, such as Ubuntu or Fedora, you can typically find a terminal emulator in the applications menu under “System Tools” or “Utilities.” These emulators include GNOME Terminal, Konsole, and Xfce Terminal. After opening the emulator, you’ll see a prompt where you can input Bash commands.

How do I open the Bash command in macOS?

To open Bash in macOS, launch the Terminal app, which typically starts a Bash session automatically. You can find Terminal in the Applications folder or use Spotlight search. Once opened, you can start typing Bash commands directly. If needed, you can explicitly start a new Bash session by typing bash and pressing Enter.

How do I open the Bash command in Windows?

To open the Bash command in Windows, enable the Windows Subsystem for Linux (WSL) via the Control Panel, install a Linux distribution from the Microsoft Store, and launch it to access the Bash terminal. Alternatively, third-party terminal emulators like Git Bash or Windows Terminal provide access to Bash along with other command-line tools.

Related Articles


<< Go Back to [Solved] “bash: command not found” Error | Bash Error Handling and Debugging | Bash Scripting Tutorial

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
icon linux
Mohammad Shah Miran

Hey, I'm Mohammad Shah Miran, previously worked as a VBA and Excel Content Developer at SOFTEKO, and for now working as a Linux Content Developer Executive in LinuxSimply Project. I completed my graduation from Bangladesh University of Engineering and Technology (BUET). As a part of my job, i communicate with Linux operating system, without letting the GUI to intervene and try to pass it to our audience.

Leave a Comment