Skip to content

How to Fix Linux sudo: command not found Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Linux sudo: command not found Error. We cover key concepts, practical examples, and best practices.

You type sudo and get command not found — sudo is not installed on the system, or the PATH does not include /usr/bin or /usr/local/bin.

The Problem

bash: sudo: command not found

Step-by-Step Fix

Step 1: Check if sudo is installed

which sudo

Or:

ls /usr/bin/sudo

Step 2: Install sudo as root

Switch to root:

su -

Then install sudo:

Debian/Ubuntu:

apt update && apt install sudo

RHEL/Fedora:

dnf install sudo

Alpine:

apk add sudo

Step 3: Add user to sudoers

As root:

usermod -aG sudo username

Or on RHEL-based:

usermod -aG wheel username

Step 4: Verify sudo group membership

groups username

Step 5: Ensure /usr/bin is in PATH

export PATH=$PATH:/usr/bin:/usr/sbin

Add to ~/.bashrc:

echo 'export PATH=$PATH:/usr/bin:/usr/sbin' >> ~/.bashrc

Step 6: Test sudo

sudo whoami

Expected:

root

Step 7: Configure sudo without password (optional)

visudo

Add:

username ALL=(ALL) NOPASSWD: ALL

Prevention Tips

  • Install sudo during OS installation
  • Use su - as fallback when sudo is unavailable
  • Add users to the sudo/wheel group after account creation
  • Include sudo in base Docker images
  • Do not modify sudoers file directly — use visudo

Common Mistakes with sudo command

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How do I run a command as root without sudo?

Use su -c "command" to run a single command as root, or su - to switch to a root shell. On some systems, doas is an alternative lightweight substitute for sudo.

Why does sudo work but still say command not found?

The command may not be in root's PATH or the secure_path configured in /etc/sudoers. Add the directory to secure_path with visudo, or use the full path to the command.

What is the difference between sudo and su?

sudo runs a single command with elevated privileges using the user's own password. su switches to another user (usually root) and requires the target user's password. sudo is more secure because it logs all commands and allows granular permissions.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro