How to Fix “sudo: command not found” Error on Linux

by Joana Maria
11 minutes read

How to Fix “sudo: command not found” Error on Linux

Sudo Command Not Located Pitfall Service

Intermittently, while implementing management job-related favor arranging a contemporary Linux desktop for a virtual equipment or revolutionizing contraption documents, you can encounter an disparaging slide post proverb sudo: command not located. This is a unremarkable and unsatisfactory unhappiness for contemporary Linux users who are simply start out.

This write-upwards affirms you what this disparaging slide techniques and how to solve it in Linux gaining make service of of opposite techniques.

Note: This tutorial provided Ubuntu 24.04 LTS as an instance, but the takes care of issued are applicable to opposite other Linux distributions also.

Content
  • What Is the Sudo Command?
  • What “Sudo: Command Not Located” Medians
  • How to Operating out Sudo: Command Not Located Pitfall
  • Placing Sudo
  • Adding User to Sudo Team
  • Add Sudo’s Directory to the Trail Variable

What Is the Sudo Command?

Let’s initially recognize what sudo is with one voice around. The sudo command, quickly for superuser implement, lets you implement job-related that require unconventional superuser (or root) privileges.

In Linux, secure user accounts have limited approvals to stay translucent of unplanned contraption devastation. You can’t availability specific documents or execute pivotal job-related. Meanwhile, the root user has no such constraints and can implement anything on the contraption.

By gaining make service of of sudo before a command, you for a moment boost your privileges. This permits you to implement commands that would certainly or else be limited. For instance, if you should mount software or equalize contraption documents, sudo offers you the mandatory approvals.

Gleaning make service of of sudo is a more detailed substitute than logging in as the root user since it declines the perplex of accidentally going versus the contraption. As shortly as you run a command doning sudo, it asks for your user password (not the root password) to prove your identification. This lends an nonessential layer of defense, wherein lone permitted users can implement sensitive operations.

In addition, there is similarly a means in which you can use sudo without a password.

What “Sudo: Command Not Located” Medians

The sudo: command not located disparaging slide techniques that your Linux contraption doesn’t have the sudo package accessible. The majority of Linux mechanisms come doning sudo pre-ranked, but a few worn’t, such as Arc and Gentoo Linux.

Yet, occasionally you still evaluate the disparaging slide even yet your contraption has sudo ranked. In that instance, it can be since your PATH variable doesn’t have the directory site wherein sudo is ranked. The PATH variable helps the contraption situate commands by brushing doning listed directory site sites.

Last but not the terribly least, you can evaluate this disparaging slide if your user deficits the applicable approvals or if the PATH isn’t place sufficiently. In addition, make certain that you have spelled sudo correctly.

How to Operating out Sudo: Command Not Located Pitfall

To solve the sudo: command not located disparaging slide in Linux, you should mount sudo, add the user to the sudo team, or add the sudo executable route to the PATH variable.

Placing Sudo

To start, let’s initially evaluate if your contraption has a sudo package accessible or not. You can comfortably evaluate by querying its iteration digit. If it arrives, then you recognize that sudo is ranked in your contraption:

sudo --version
inspecting iteration of sudo in Linux terminal.

If your Linux contraption implements not have sudo ranked, you’ll should mount it to encompass the disparaging slide. For this, you should log out of your user account and log in as a root user.

To implement that, entirely kind this command:

su -

Presently, after becoming a root user, you can mount the sudo package in your Linux circulation gaining make service of of your default package manager.

For instance, you can mount sudo in Ubuntu/Debian-based distributions gaining make service of of apt:

apt install sudo

To mount sudo in CentOS/Fedora or RHEL-based distro, run this:

dnf install sudo

Utilise the obeying command to mount sudo package on Arc Linux:

pacman -S sudo

Adding User to Sudo Team

After posing sudo, add your non-root user to the sudo team to enable superuser root availability. For instance, you can add a user to the sudo team in Ubuntu or Debian contraption by gaining make service of of this command:

usermod -aG sudo username

On Fedora/CentOS or opposite other RHEL-based distros, hazard containing a user to the wheel team:

usermod -aG wheel username

In addition, you can prove whether the user contained to the team or not by implementing the beneath command:

groups username

After inspecting, switch ago to the non-root user from the root gaining make service of of the su command abided doning by your username:

su username

That’s it! Presently, you can comfortably implement with one voice the commands as a superuser gaining make service of of sudo. For instance, you can prove the sudo installation by simplifying the packages of your Linux contraption doning this command:

sudo apt update
simplifying package gaining make service of of the proper package manger.

Add Sudo’s Directory to the Trail Variable

If you have sudo ranked on your contraption but bolster to procure a sudo: command not located disparaging slide, then evaluate your PATH variable and make certain it requires the directory site wherein sudo is ranked.

First, recognize the recognize of your sudo command by reverting its executable route:

which sudo
inspecting route of the sudo gaining make service of of which command.

Next off, use the echo command to evaluate if your PATH variable requires this directory site (/usr/bin/):

echo $PATH
Sudo Variable Trail
How to Fix "sudo: command not found" Error on Linux 14

Here, you evaluate a list of opposite directory site sites distinguished by colons. You should filter for “/usr/bin” or “/bin” in the list since they are the opposite unremarkable places for sudo.

If you worn’t have “/usr/bin” directory site in your PATH, you can entail it doning this command:

export PATH=$PATH:/usr/bin

In addition, equalize “/usr/bin” doning the actual directory site that has the sudo executable.

Sprinting this command for a moment modernizes the PATH variable, making it possible for your contraption to situate the sudo directory site and encompass the bash puzzles in Linux. Yet, this improvement is quickly-lived and will disappear as shortly as you expire the terminal session.

To make this equalize long-term for with one voice users, you should add the sudo directory site to the contraption-wide PATH variable. To implement that, let’s initially come to be the root user:

su -

Open the “/etc/profile” record:

nano /etc/profile

Scour for the variable route queue and add your “/usr/bin” directory site to the PATH variable.

Last but not the terribly least, preserve the record by pressuring Ctrl + O and chummy the editor. Presently, you can job-related doning the sudo command without any puzzles.

Wrapping Upward

You have fruitfully straightened out the sudo: command not located disparaging slide by posing sudo, containing your user to the sudo team, and containing the sudo executable route in the PATH variable.

In addition, you can similarly dissect the differences in between sudo -s, su, sudo su, and sudo -i.

Image credit report: Haroon Javed

Related Posts