Interested in discovering how to resolve the “sudo: command not found” error on Linux? This issue can significantly impede your productivity as a Linux user. The pivotal term in Linux is ‘sudo,’ denoting the superuser who holds permissions to execute various system modifications. While sudo packages are typically preinstalled on most Linux distributions, there may be instances where they are not available.
Therefore, if you try to use the sudo Command on a system without sudo installed, an error “sudo: command not found” is displayed. If you run various tasks on your system using sudo keywords, you may encounter the problem of “sudo command not found.” The sudo Command is the primary Command used to perform management operations safely. Let’s dive into this article to learn about how to fix the “sudo: command not found” error on Linux.
Sudo command on Linux
Sudo stands for superuser do, a program that allows users to run commands and programs with root or promoted permissions. Running a Linux system using sudo instead of root users is usually recommended. It reduces the risk of system destruction when potentially dangerous commands are executed. Sudo packages are bundled with most Linux distributions by default, and there should be no problem using them. However, this does not necessarily apply to all Linux distributions. Some exceptional cases do not have sudo installed on the system.
The sudo Command cannot be found. “The Error does not need to be worried, and you do not need to worry if you encounter this Error. While working with Linux systems, we recommend using sudo instead of root users. It reduces the likelihood of potentially dangerous Linux commands crashing the system. Most Linux distributions contain sudo packages by default, so using them should be fine. Here you can learn about How to fix Hulu error code 502.
Common Causes of “sudo: command not found” Error
Lack of sudo installation
One of the most common causes of sudo: Command not found “error is that the system does not have a” sudo “package. Depending on the Linux distribution, ‘sudo ‘may not be preinstalled, so it must be installed manually.
Incorrect System Settings
The “sudo” Command may not be recognized if the system setting is incorrect, such as a PATH variable configuration error. It can happen when you move, rename, or delete system files or directories.
Environment Variable Problems
“Sudo: command not found” Error may occur if an environment variable such as PATH is problematic. Due to these variable problems, the system may not find a sudo binary.
User privileges and PATH settings
User privileges and PATH settings may also be involved in this Error. If the user does not have the necessary permissions to run sudo ‘or the PATH is not set correctly, they may face this problem.
Methods to fix “sudo: command not found” on Linux
If sudo is not installed, root user privileges cannot be assumed, so you must log out of the user account and log in as root. As a root user, you can install sudo packages with the privileges of this account, so it is not subject to Linux’s “sudo command not found” Error.
1: Install Sudo Utility
The most common reason is that sudo is not installed on the system. Let’s glimpse how you can install it:
- Check if sudo is present: Before entering the installation phase, first, check whether sudo is installed on the system using the Command
- Install sudo: First, you need to switch to the root user by employing the Command
- Then install the sudo utility on your system using one of the commands corresponding to your Linux distribution
2: Add a user to a sudo group
To fix this Error, you must add the user to a sudo group or a line such as wheel, admin, etc. Follow these steps:
- Login as root user
Login as root user and modify to add “user” to the “sudo” group
- Add users to the sudo group
- Now, replace the “usermod -aG sudo username” command with the username to add “username” to the sudo group. In this case, the existing username is “itslinuxfoss”:
- Make sure it’s added to the sudo group
- Log out and log in again to see who has been added to the sudo group. To do this, replace the added username with the “groups username” command:
- Reinstall the sudo Command
- Then reinstall the sudo Command with the root user and modify all dependencies with the following Command:
- After reinstalling the sudo package, you may need to log out to enable the changes.
- Check Full Access to Sudo
- Enter the sudo -l command and verify that you can execute the sudo Command. You will see a message like “User username may run the following commands on this host: (ALL: ALL) ALL,” and you will know that you have full sudo access:
Finally, this Error is resolved on Linux and executes the Command as a superuser when necessary.
3: Setting/Updating Path Variables
If the first solution did not work, you need to add/update the path variable of the sudo executable. If you are still, please do the following steps:
- Open the .bashrc file
- Open the .bashrc profile using any editor as the root user, such as Nano or Vim.
- Path: Add variables.
- Scroll down the file and add the following line /usr/bin is the directory with the sudo executable.
4: Delete or restore Aliases or functions in sudo
Use the “unalias” or “unset” Command to resolve this Error. You must edit the bashrc file to delete or restore sudo aliases or functions. You can use the unalias or unset Command to delete aliases or functions depending on how sudo is defined.
Read more: No Results Found: How To Fix Errors in Windows Search?
- Delete sudo aliases
To delete an alias, use the “unalias” Command in sudo. If sudo is defined as an alias, run the following script:
- Delete sudo functions
If sudo is defined as a function, force the “unset” Command to flag “f” and execute the following script:
- Restoring aliases or functions
To restore an alias or function, locate where it was initially defined and re-source the file. For example, if sudo was described in the .bashrc file, it can be executed as follows:
- Reinstall/install sudo Command
To reinstall or install the ‘sudo’ command on any Linux-based system, utilize the apt package manager with the following instructions:
5: Add/usr/bin to the PATH variable
To solve this problem, use the export command or. You must edit the bashrc file and add/usr/bin to the “PATH” variable. Step-by-step steps are as follows:
- PATH See the current value of the variable
Open the terminal and enter the “echo $ PATH” command to see the current value of the PATH variable:
- PATH Adding variables
To add/usr/bin to the PATH variable, edit ~/.bashrc, the configuration file of the bash shell. For example, use the nano editor and enter the following Command.
- Append the following line to the conclusion of the file. It adds/usr/bin to the existing PATH variable to be searched first.
- Reload Source Files
To apply the changes, you must restart the terminal or type this Command to source the file:
- Reinstall the sudo Command
To reinstall the sudo “Command, use the apt package manager if it is a Linux-based system.
Frequently Asked Questions
1. Why does the error “sudo command not found” occur?
A: This Error occurs for various reasons, such as the sudo package missing, the PATH variable incorrect, installation incomplete, permission problem, etc.
2. How do I check if the sudo package is installed?
A: Open the terminal and type “which sudo.” It is installed if the path to sudo e.g.,/usr/bin/sudo is returned.
3. Is there an alternative to using “sudo” on Linux?
The main alternative to sudo is to switch to a root prompt whenever you manage on a Linux system. It’s inconvenient, but it helps you understand that you are switching to a mode with more permissions. Just remember to return to the average user immediately afterward. Overall, it is safer and convenient to install and use “sudo” instead, but the choice is up to you.
4. Is it safe to add users to the sudoers file?
When you add a new user to the sudoers file, the user becomes the system administrator and has all the privileges of the computer. It is safe to trust the user but ensure the user understands the meaning.
Conclusion:
We outlined the underlying issue and provided instructions on how to resolve it, including tasks like transitioning to root users, installing sudo across different Linux distributions, adding users to the relevant group, and granting sudo privileges. This not only mitigates the risk of recurring errors but also guarantees seamless and effective Linux usage. In case the problem persists, consider opting for fresh installations or changing distributions. Keep in mind that a solid understanding and adaptability to these issues are key when working with Linux operating systems.
Read more: