sudo command not found on linux

How to Fix: “sudo command not found” on Linux (2 reasons)

If you click our links and make a purchase, we may earn an affiliate commission. Learn more

You’ve spent time installing your new Linux system, you’re ready to start installing packages for your projects, and then bam: “sudo command not found”. Nothing works. It’s a real bummer, but don’t worry, you’ve come to the right place. I’ll quickly explain how to fix this error.

In general, the error “sudo command not found” happens when the sudo package is not installed on the system. This can be fixed by switching to the root user and installing the missing package.

Not sure how to do this? Don’t worry, I’ll guide you through each step to help you identify the exact problem and fix it. In some cases, it might be something else, so I’ll quickly cover that as well.

If you need help with Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your system. Click here to get it for free!

Case 1: Sudo is not installed

There are some light Linux distributions (like the minimal version of Debian) that are installed without sudo by default. The root account is enabled, but it can’t use sudo from the default user.

In this case, if you try to use sudo as a prefix for any command, you’ll get the error:
-bash: sudo: command not found

This is the most common case, so I’ll address it right away.

How to know if sudo is installed?

If you get the same error as me in my previous screenshot, it’s most likely because sudo is not installed. But there is a command you can try to confirm that is the case.

On Linux, the command “which” tells where the executable is installed. If the command returns nothing, it means the package is not installed.

So, in my example, I can try:
which sudo
I get nothing in the result, which means sudo is not installed.

If the “which” command returns something, you are probably in the second case addressed in this article, so you can skip a few paragraphs to get right to it.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now
Prefer reading without ads and popups?
Members get an ad-free version of every guide, plus exclusive project support.
Join the Community | Sign In

Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.

How to install the sudo package

The sudo package is available in the default repository, but installing it requires administrator permissions. You can only install it after switching to the root user.

So, obviously, if you try to use “sudo apt install sudo” to install it, it won’t work :-).

As a reminder, “sudo” is used to get temporary administrator permissions, but it’s still possible to log in as root or at least switch to the administrator prompt on most distributions.

To do this, type the following command and press Enter:
su

As you can see in my screenshot, it asks for the root password. I can then use apt without sudo:
apt update

Once done, you can now use your package manager command to install the missing package:
apt install sudo

That’s it, sudo is now installed, and we are almost done.

Note: If you are not using a Debian-based distribution, you need to adjust this command to use your own package manager. For example:
– Red Hat / Fedora:
dnf install sudo
– Arch:
pacman -S sudo
– SUSE:
zypper install sudo
– Gentoo:
emerge app-admin/sudo
You get the idea.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

Related: How to Fix the ‘apt-get command not found’ Error on Linux

How to allow the sudo command for a specific user

You can get back to the normal user terminal with this command:
exit
It will quit the administrator prompt, and get back to your own session.

From there, you shouldn’t get the error anymore:
sudo
And the “which” command should return something:

But we aren’t done yet, as the current user won’t have permission to use “sudo”. It’s an administrative command that requires privileges to be given individually to each trusted user.

To allow your current user to run sudo commands, you need to get back to the root session, and run this command:
/usr/sbin/usermod -aG sudo pat
Make sure to replace “pat” with your user name.

Note: the command “usermod” directly might not work because /usr/sbin is not in the PATH by default on some distributions (like the latest Debian I tested). That’s why I use the full path.

Once done, you need to exit both sessions and reconnect to get access to sudo from the normal user. Or you can reboot the computer if it’s possible for you. On your next log-in, sudo commands will work directly and you’ll no longer need to switch to “root”.

Case 2: Sudo is not in the PATH variable

This second scenario is way less common, but as experienced with “usermod” in the previous section, it might be that sudo is installed but not in the PATH.

In short, the PATH variable on Linux tells the system where to look for the command executables. The sudo command won’t work if the executable is installed in a directory that is not included in this PATH variable.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

You might also like: The 5 fastest web browsers for Raspberry Pi — tested and ranked!

By default, you shouldn’t have to worry about this. But I have seen this problem a few times, so I’ll include it. Don’t worry, it’s a quick fix.

How to know if you have a PATH problem?

As a general rule, there is an issue with your PATH variable if the main command (“sudo”) doesn’t work, but the full path command (“/usr/bin/sudo”) works.

I reproduced this problem on my system, here is what it looks like:

The “sudo” command returns the same error as previously (“sudo: command not found”), but when we use the full path to the executable, it exists and works as expected.

It’s pretty rare, as most executables are in this directory, which means most commands on your system likely won’t work anymore, but it’s something I have seen. Let’s discuss how to fix it.

How to resolve the issue with your PATH variable?

To fix the PATH issue causing the “sudo: command not found”, you need to add the /usr/bin folder back to your PATH variable.

You can see your current PATH variable contents with:
echo $PATH

In this example, as /usr/bin (and /bin) are missing in my PATH, so the command doesn’t work.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

To fix this error, I need to add the executables folder back to the PATH variable:
export PATH=$PATH:/usr/bin

After adding /usr/bin to your PATH variable, it should be working:

Warning: This is a temporary fix for your current session. If your PATH is broken after a reboot or for each new session, you most likely need to fix your system configuration file.

For example, the global configuration on Debian is in this file:
cat /etc/profile

Make sure the main executables folders are included there. But if you didn’t edit this file, it shouldn’t be an issue. You can use Nano to edit this file from the administrator session if needed. Just be careful, doing a backup is probably a good idea.


🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Want to connect with other Raspberry Pi fans? Join the RaspberryTips Community. Ask questions, share your projects, and learn from each other. Join now.

Related questions

Are there any alternatives to using “sudo” on Linux?

The main alternative to using “sudo” is to switch to the root prompt each time you have administrative tasks to do on your Linux system. It’s a bit less convenient, but it can help to understand that you’re switching to a mode with more permissions.

Just don’t forget to get back to your normal user after that right away. Overall, it’s safer and more convenient to install and use “sudo” instead, but the choice is yours.

Is it safe to add a user to the sudoers file?

Adding a new user to the sudoers file basically makes it a system administrator, will all privileges on the computer. It’s safe if you trust the user, just make sure the user understands what that means.

How to remove access to the sudo command for a user?

Removing the user’s access to the sudo command can be done with the deluser command:
deluser <user> sudo

You need administrative privileges to do this, so you’ll need to prefix this command with sudo or switch to the root account.

Whenever you're ready, here are other ways I can help you:

Master Linux Commands: Overwhelmed with Linux commands? This book is your essential guide to mastering the terminal. It includes practical tips, real-world examples, and a bonus cheat sheet to keep by your side.

The RaspberryTips Community: Need help with Linux or want to chat with people who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct support.

You can also find all my recommendations for tools and hardware on this page.

Similar Posts