Skip to content

How to Fix Linux Command Not Found Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Linux Command Not Found Error. We cover key concepts, practical examples, and best practices.

You type a command and get bash: <command>: command not found — the executable is not installed or not in your shell's PATH.

The Problem

bash: htop: command not found

Or:

zsh: command not found: nvim

Step-by-Step Fix

Step 1: Check if the package is installed

dpkg -l | grep htop

Or on RHEL-based:

rpm -qa | grep htop

If no output, the package is not installed.

Step 2: Install the missing package

Debian/Ubuntu:

sudo apt update && sudo apt install htop

RHEL/Fedora:

sudo dnf install htop

Arch:

sudo pacman -S htop

Step 3: Check if the command exists but is not in PATH

which htop

Or:

find /usr -name htop -type f 2>/dev/null

If found but not in PATH, add the directory:

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

Make permanent by adding to ~/.bashrc:

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

Step 4: Verify installation

htop --version

Expected:

htop 3.3.0

Step 5: Check typo or case sensitivity

Linux commands are case-sensitive:

# WRONG
Htop
HTop

# RIGHT
htop

Step 6: Check if the command needs a different package name

Some commands have different package names:

# ifconfig is in net-tools
sudo apt install net-tools

# ping is in iputils-ping
sudo apt install iputils-ping

Prevention Tips

  • Know the correct package name for your distribution
  • Use apt search <name> or dnf search <name> to find packages
  • Keep your package list updated with sudo apt update
  • Install development tools with sudo apt install build-essential
  • Use type <command> to see how a command is resolved

Common Mistakes with command not found

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

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

### Why does my command work for root but not my user?

The command is likely in a directory not in the user's PATH but included in root's PATH (like /sbin or /usr/sbin). Run with full path /usr/sbin/command or add the directory to your PATH.

How do I find which package provides a command?

Use apt-file search <command> or dnf provides <command>. Install apt-file with sudo apt install apt-file && sudo apt-file update, then search.

What is the difference between command not found and permission denied?

"Command not found" means the shell cannot locate the executable. "Permission denied" means the executable exists but lacks execute permission. Fix with chmod +x <file>.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro