Facebooktwitterredditpinterestlinkedintumblr

The sudo command is used to execute applications with root privileges. Sometimes, when trying to use the sudo command, it will give an error message that says sudo: command not found.

This can be frustrating if you are using the sudo command for something important like updating packages or installing programs. Here are some ways to fix this problem and get back up and running.

Method 1: Check Path to sudo

By default, sudo should be installed on your Linux system. If not, it’s possible sudo is not in your path for some reason.

Use the exact path to sudo by running:

$ /usr/bin/sudo -V
-bash: /usr/bin/sudo: No such file or directory

If you get the error above, it means sudo isn’t installed in your system. If so, continue with the next method.

If the above command works, it could mean the your PATH variable is not correct. Find out what is your current PATH variable:

echo $PATH

If /usr/bin is missing from your PATH variable, update it by adding /usr/bin to your current PATH variable.

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

Adjust the PATH variable to what you current have listed when you type echo $PATH.

Method 2: Install sudo

The command sudo is a much-needed tool when working in Linux. If you type something like sudo fdisk -l, only to find out that it doesn’t work because of an error such as “sudo: Command not found,” then your distribution may not have this essential module installed.

To find out for sure, type the following command:

$ whereis sudo
/usr/bin/sudo

If you don’t get the output above, it means the sudo program is not installed.

If you’re on Debian, you install sudo by first logging in as root by typing this command:

su -

Another option is to hold down the Ctrl + Alt + F1 key combination to switch to a text terminal. Log in as username root and specify the password for the root user. After logging in, there should appear # at the command prompt.

So, if you have a Linux system based on the apt package manager, then run this command to update the system package list.

apt update

Next step is to install sudo on your system.

apt-get install sudo -y

Those who are using Fedora, Red Hat Linux, CentOS, and Scientific Linux, you can type this command:

yum install sudo

At this point, you want to add your username to the sudo group so that your own user has sudo rights. Change username to your own user (e.g., jeff).

usermod -aG sudo username

At the root prompt, you need to add yourself to the sudoers file at /etc/sudoers by running:

visudo

When you see the text editor, enter the line below.

%sudo ALL=(ALL) ALL

If you’re using the vi editor, type :wq to exit and save the file. If you’re using the nano editor, press Ctrl + O key combination to save the file and Ctrl + X key combination to exit the nano editor.

After you’re done, reboot your computer for changes to take effect.

Conclusion

When it comes to permissions, the root user can do whatever they want. However in order for these commands and changes be made securely, you need either a sudo or an account with administrator privileges.

We’ve discussed solutions involving checking if sudo is installed and installing sudo manually if it isn’t installed.

Leave a Comment