What Is “sudo” in Linux?
User accounts on Linux come with a limited set of privileges that prevent them from performing administrative tasks which may damage the system. These limited privileges may keep users from accessing certain areas of the filesystem or from executing certain files.
The one user who has no such restrictions on their actions is the root user. The root user can access any area of a Linux system, and execute any command on any file.
Because of this immense power, you should disable the root account and use sudo instead.
The sudo command is short for “superuser do” and allows a user who is part of the sudo group to execute a command as if they were the root user. It effectively gives them root powers and permissions—as long as they use sudo and authenticate with a password.
Why Is the sudo Command Not Found?
As well as being a useful command, sudo is a package. On most systems, sudo is installed by default. But this is not the case on all distros, and when you attempt to run a command using sudo you may receive the error, “sudo: command not found”. This is especially common on newly installed Linux systems.
You may then try to install the sudo package with:
This will fail because you are unable to use sudo to install packages as the root user.
How to Fix “sudo: command not found” on Linux
As your user cannot assume the privileges of the root user without already having sudo installed, you need to log out of your user account and log in as root.
As root, you can install the sudo package with the privileges this account possesses.
On Debian-based systems, enter:
Then, add your user to the sudo group using:
On Arch-based systems, enter:
Then:
You Can Now Run Commands With sudo on Linux!
You have successfully installed sudo and added your user to the sudo group, meaning that you can run any command and access any area without needing to log in as root. Use this power carefully, as elevated privileges can be dangerous.