Download Article
Troubleshoot the “sudo command not found” error on any Linux distro
Download Article

If you receive a "sudo command not found" error when trying to run a sudo command in Linux, it either means the sudo package is not installed, or the sudo directory is not in PATH variable. Luckily, you can fix this error with a few simple terminal commands.

Why "Sudo Command Not Found" Happens

You might see a "sudo command not found" error if the sudo package is not installed on your Linux distribution or if the sudo directory is missing from the PATH variable. Your username may also need to be added to the sudo group.

Method 1
Method 1 of 2:

How to Install Sudo

Download Article
  1. To install the sudo package, you must become root . Type sudo su - , press Enter , and then
    • Enter the root user password.
    Advertisement
  2. Enter one of the following commands to install the sudo package based on your Linux distribution:
    • Debian/Ubuntu: Type apt update -y and press Enter , then type apt install sudo and press Enter .
    • Fedora/CentOS/Rocky/Alma Linux: Type yum install sudo and press Enter .
    • Arch Linux/Manjaro: Type pacman -S sudo and press Enter .
    • Gentoo: Type emerge --ask app-admin/sudo and press Enter . [1]
  3. After you install the sudo package, you need to add anyone who needs access to the sudo command to the "sudoers" group. To do this, type usermod -aG sudo [username] and press Enter .
    • Replace "[username]" with the username you want to add.
  4. Use the following command to do so:
    • Type su [username] and press Enter . Replace "[username]" with your actual username.
    • You should now be able to use sudo . You can test it by typing sudo followed by the command you want to run.
  5. Advertisement
Method 2
Method 2 of 2:

How to Add Sudo to Your Path

Download Article
  1. This will check if sudo's directory is in PATH. If it is in your path, you should see /usr/bin as one of the directories (the most common install location). However, sudo may also be installed in /usr/local/bin, /opt/bin, /bin, or /srv/bin. If the directory where sudo is installed is not listed in your path, continue to the next step.
    • If /usr/bin or any of these other directories aren't in your path, you've probably also noticed that other commonly used commands are also giving you "command not found."
    • If you're not sure where sudo is installed, use this guide to learn how to find files in Linux.
  2. After adding this directory to your PATH variable, sudo should be working. [2]
    • Type export PATH=$PATH:/usr/bin and press Enter .
    • This command is temporary and only applies to the current terminal window. To permanently add /usr/bin (or whichever directory sudo is installed) to the system path for all users, open /etc/profile in your favorite text editor, then add /usr/bin (or the directory where sudo is installed) to the directories in the path.
  3. Advertisement

Expert Q&A

Ask a Question
      Advertisement

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!

      About This Article

      Thanks to all authors for creating a page that has been read 3,528 times.

      Is this article up to date?

      Advertisement