How to Fix Linux Command Not Found Error
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>ordnf 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
- Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro