What the "command not found" error means
The bash: command not found (or command not found) error means that the Bash shell cannot find the executable file for the command you entered in any of the directories specified in the PATH environment variable.
The full error message typically looks like this:
$ somecommand
bash: somecommand: command not found
This error occurs at the moment you enter a command in the terminal (interactive mode) or when executing a script. Bash sequentially searches for an executable file named somecommand in each directory from the PATH variable. If no file with that name is found in any of them (or it lacks execute permissions), you receive this message.
Common causes
- The package containing the command is not installed. The most frequent cause. The command is part of a software package (e.g.,
git,docker,htop) that you have not installed. - The command is located in a directory missing from
PATH. You installed the program in a non-standard location (e.g.,~/apps/or/opt/local/bin), but that path is not added to thePATHvariable. - Typo or incorrect case. Linux commands are case-sensitive.
Ls≠ls. - The executable file is missing or has incorrect permissions. The command file was deleted, moved, or lacks execute permission (
chmod +x). PATHis corrupted or misconfigured. ThePATHvariable might be empty, contain syntax errors, or include relative paths.
How to resolve it
Method 1: Check for typos and case
Before deep diagnostics, ensure the command is spelled correctly.
- Use the
Tabkey for autocompletion. If Bash does not complete anything, the command is likely unknown to the system. - Verify the case:
git status, notGit Status. - To search for similar commands, use
apropos <keyword>(requires an up-to-date man-page index).
Method 2: Find and install the missing package
If the command is standard (e.g., curl, wget, python3), you need to install it.
For Ubuntu/Debian:
# Search for the package containing the command
apt search <command_name>
# Install the package (requires sudo)
sudo apt update && sudo apt install <package_name>
For CentOS/RHEL/Fedora:
yum provides */<command_name> # or dnf on Fedora/CentOS 8+
sudo yum install <package_name>
For Arch Linux:
pacman -Fs <command_name>
sudo pacman -S <package_name>
Method 3: Check and fix the PATH variable
- View your current
PATH:echo $PATH
The output will look like/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin. This is the list of directories where Bash searches for commands. - Determine where your command is located (if it exists on the system):
# Will show the full path to the executable if found in PATH which <command_name> # More accurate check (bash builtin) type -a <command_name>
Ifwhichproduces no output, the command is not in yourPATH. - If you know where the command resides but it's not in
PATH, add the directory temporarily (until you close the terminal):export PATH=$PATH:/full/path/to/command/directory
After this, the command should work. - To add the path permanently, edit your shell's configuration file.
- For Bash (default on most distributions), open
~/.bashrcor~/.profileand add:
export PATH="$PATH:/full/path/to/directory"- For Zsh, edit
~/.zshrc. - After saving the file, run
source ~/.bashrc(orsource ~/.zshrc) for the changes to take effect in the current session.
- For Bash (default on most distributions), open
Method 4: Check file execute permissions
If the command is your own script or program, ensure the file is executable.
# Check permissions
ls -l /full/path/to/command_file
# Output should show 'x' for owner/group/others (e.g., -rwxr--r--)
# If not — add execute permission:
chmod +x /full/path/to/command_file
Also ensure the file is located in a directory that is present in your PATH.
Prevention
- Be mindful of your
PATH. Don't add too many directories to it. Standard paths (/usr/local/bin,/usr/bin) should be present. - Use absolute paths in scripts for critical commands if you are unsure about the execution environment.
- Create aliases for frequently used long commands in
~/.bashrc:alias ll='ls -la' - Check for command existence before writing complex scripts using
command -v <command_name>ortype <command_name>. This is more reliable thanwhich. - After manually installing software (from source or into
/opt), immediately add its binary directory to yourPATH.