Error "command not found" in Linux
The error "bash: command not found: command" (or "zsh: command not found: command" in Zsh) is one of the most common issues in the Linux terminal. It means that the shell could not find the executable file for the specified command in the system paths.
Causes of the Error
There are several main reasons for the command not found error:
- Command not installed — the required package is simply not installed on the system
- Incorrect PATH — the directory with the command is not added to the PATH environment variable
- Typo in the name — the command was entered incorrectly or with the wrong case
- Lack of execution permissions — the file exists but does not have the executable attribute
Diagnosing the Error
1. Check for Typos
# Example of a typo
$ pyton --version
bash: pyton: command not found
# Correct version
$ python3 --version
Python 3.10.12
2. Check the PATH Variable
echo $PATH
Typical output:
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
If the required directory is missing, add it:
# Temporary addition (valid until the terminal is closed)
export PATH=$PATH:/usr/local/myprogram/bin
# Permanent addition (for the current user)
echo 'export PATH=$PATH:/usr/local/myprogram/bin' >> ~/.bashrc
source ~/.bashrc
3. Find the Command's Location
# Search for the command in PATH
which python3
# Output: /usr/bin/python3
# Find all files related to the command
whereis python3
# Output: python3: /usr/bin/python3 /usr/bin/python3.10
# Show the type of command (builtin, alias, function)
type python3
4. Check if the Package is Installed
# For Debian/Ubuntu
dpkg -l | grep <package_name>
apt list --installed | grep <package_name>
# For CentOS/Fedora/RHEL
rpm -qa | grep <package_name>
dnf list installed | grep <package_name>
Solutions
Installing Missing Commands
Ubuntu/Debian
sudo apt update
sudo apt install <package_name>
# Example: installing curl
sudo apt install curl
CentOS/RHEL
sudo yum install <package_name>
# or
sudo dnf install <package_name>
Arch Linux
sudo pacman -S <package_name>
Common Commands
| Command | Package (Debian/Ubuntu) | Package (CentOS) |
|---|---|---|
curl | curl | curl |
wget | wget | wget |
git | git | git |
nano | nano | nano |
vim | vim | vim |
python3 | python3 | python3 |
Prevention
- Regularly update the system — this ensures that you have the latest versions of packages
- Use autocompletion — press
Tabfor automatic command completion - Check the documentation — review dependencies before installing new software
- Create aliases — for frequently used commands with long paths
Conclusion
The command not found error is rarely a serious problem and is usually easily resolved by installing the appropriate package or correcting the PATH variable. By following the diagnostic steps outlined above, you can quickly identify and resolve the cause of the error.
If the problem persists after following all recommendations, check the system logs or consult the documentation for your specific Linux distribution.