LinuxMedium

Bash command not found: causes and 4 ways to fix

This article explains why the 'command not found' error appears in the Linux terminal and offers 4 practical ways to fix it: from checking typos to configuring the PATH variable.

Updated at February 15, 2026
5-10 min
Easy
FixPedia Team
Применимо к:All Linux distributions (Ubuntu, Debian, CentOS, Arch)Bash 3.2+

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

  1. 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.
  2. 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 the PATH variable.
  3. Typo or incorrect case. Linux commands are case-sensitive. Lsls.
  4. The executable file is missing or has incorrect permissions. The command file was deleted, moved, or lacks execute permission (chmod +x).
  5. PATH is corrupted or misconfigured. The PATH variable 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 Tab key for autocompletion. If Bash does not complete anything, the command is likely unknown to the system.
  • Verify the case: git status, not Git 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

  1. 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.
  2. 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>
    

    If which produces no output, the command is not in your PATH.
  3. 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.
  4. To add the path permanently, edit your shell's configuration file.
    • For Bash (default on most distributions), open ~/.bashrc or ~/.profile and add:
    export PATH="$PATH:/full/path/to/directory"
    
    • For Zsh, edit ~/.zshrc.
    • After saving the file, run source ~/.bashrc (or source ~/.zshrc) for the changes to take effect in the current session.

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> or type <command_name>. This is more reliable than which.
  • After manually installing software (from source or into /opt), immediately add its binary directory to your PATH.

F.A.Q.

Why does the command work with sudo but not for a regular user?
Can I add a folder with commands to PATH permanently?
The error occurs only for one specific command. What should I do?
Am I writing the command correctly? Is the 'command not found' error due to a typo?

Hints

Check the command spelling
Check if the package containing the command is installed
Locate the executable file
Check the PATH variable value
Add the missing directory to PATH
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community