This is one of the most common problems new Linux users face after a fresh installation.
Here’s how you’re free to solve this issue and start using the sudo command again.
For this tutorial, I’ll be demonstrating everything on Debian 12.
Lucas Gouveia/How-To Geek |monticello/Vegorus/Shutterstock
What Is the sudo Command?
With sudo, authorized users can perform administrative tasks without needing to sign on as the root user.
The way to use sudo is to begin another command with the word “sudo”.
This allows you to launch the command with elevated privileges.
So the sudo command lets you have the required permissions of a different user and run a sensitive command.
you’re free to learn more about the sudo command from itsmanual page.
Why Are You Getting This Error?
There are usually two possible reasons for the “sudo: command not found” error on Linux.
Some Linux distributions may not have the sudo package installed by default.
This is true for Arch and Gentoo Linux.
On Debian, if you set a root password during installation, then you’ll face the same problem.
The second reason is that sudo is installed, but its directory is not included in the PATH variable.
PATH is an environment variable the Linux system uses to locate a command without specifying its full path.
Install sudo on Linux
To roll out the sudo package, you should probably becomerootfirst.
As a root user, you might install any software package, including sudo.
This is because you want to give that user superuser privileges.
Then your non-root user can use the sudo command to gain elevated privileges.
For example, let’s give a shot to update the packages on the system.
To do that, use:
It works as expected.
Let’s first determine the location of the sudo command.
As you’ve got the option to see, it’s in the “/usr/bin/” directory.
Now let’s verify if the directory is in the PATH variable or not.
After you end the terminal session, things will go back to what they were.
To permanently add the directory, launch the “/etc/profile” file in a text editor.
Save the file using Ctrl+O and then exit from the editor using Ctrl+X.
Now venture to use the sudo command to see if it’s working.
That should solve your problem and let you use the sudo command without any errors.
Remember that, only the users added to the sudo group will be able to use it.