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.
Steps
-
Press Ctrl + Alt + T to open the Terminal . You can use the keyboard shortcut to open the terminal on most versions of Linux.
- Most Linux distributions come with the sudo package installed. This method mostly only applies if you're using Gentoo, Arch Linux, or if you installed Debian with a root password.
-
Log in as root. To install the sudo package, you must become root . Type sudo su - , press Enter , and then
- Enter the root user password.
Advertisement -
Enter the command to install the sudo package. 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] X Research source
-
Add your user account to the sudo group. 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.
-
Switch back to your regular username. 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.
Advertisement
-
Press Ctrl + Alt + T to open the Terminal . You can use the keyboard shortcut to open the terminal on most versions of Linux.
-
Type echo $PATH and press ↵ Enter . 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.
-
Export the "user/bin" folder to the PATH variable. After adding this directory to your PATH variable, sudo should be working. [2] X Research source
- 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.
Advertisement
Expert Q&A
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Tips
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
References
About This Article
Thanks to all authors for creating a page that has been read 17,385 times.
Advertisement