“Command not found” is a shell error that appears when the terminal cannot locate an executable file matching the name you typed. It happens on Linux, macOS, and Windows (in Command Prompt or PowerShell) when the command is misspelled, not installed, or not in the system’s PATH. This article explains why the error occurs and gives step-by-step fixes for each operating system.
What “Command Not Found” Actually Means
When you type a command, the shell (Bash, Zsh, fish, cmd.exe, or PowerShell) looks for an executable file with that exact name. It searches the directories listed in the PATH environment variable, in order. If no match is found, the shell returns an error message. On Linux and macOS, the message is typically command not found. On Windows Command Prompt, it’s 'xxx' is not recognized as an internal or external command, operable program or batch file. PowerShell says The term 'xxx' is not recognized as the name of a cmdlet, function, script file, or operable program.
The error does not mean your system is broken. It simply means the shell couldn’t find the program you asked for. The most common causes are:
- A typo in the command name (e.g.,
pythnoinstead ofpython). - The software is not installed.
- The software is installed but its directory is not in your PATH.
- You’re using a different shell or user account that has a different PATH.
- The command requires a specific interpreter (e.g., a Python script needs
python script.py).
How the PATH Environment Variable Works
PATH is a list of directories separated by colons on Linux/macOS and semicolons on Windows. When you type a command, the shell checks each directory in order. If the executable is in one of those directories, it runs. If not, you get “command not found.”
To see your current PATH, run:
- Linux/macOS:
echo $PATH - Windows Command Prompt:
echo %PATH% - Windows PowerShell:
$env:PATH
If the directory containing the program is not listed, the shell won’t find it even if the program is installed. This often happens after installing software that doesn’t automatically add itself to PATH, such as Python, Node.js, or Java on Windows, or when using a version manager like Homebrew on macOS (which installs to /opt/homebrew/bin on Apple Silicon).
Fix 1: Check for Typos and Quoting
The simplest fix is to verify the spelling. Shell commands are case-sensitive on Linux and macOS, but not on Windows. For example, LS will fail on Linux but work on Windows. Also, if the command contains spaces, you must quote it or escape the spaces. For instance, to run a program named My App, you need "./My App" or ./My\ App.
If you’re trying to run a script in the current directory, you often need to prefix it with ./ on Linux/macOS. The current directory is usually not in PATH for security reasons. So script.sh will fail, but ./script.sh will work if the file is executable.
Fix 2: Install the Missing Command
If the command is a well-known tool, it’s likely not installed. Use your package manager to install it.
- Debian/Ubuntu:
sudo apt install <package> - Fedora/RHEL:
sudo dnf install <package> - Arch:
sudo pacman -S <package> - macOS (Homebrew):
brew install <package> - Windows (Chocolatey):
choco install <package> - Windows (winget):
winget install <package>
If you’re not sure which package provides the command, search online or use apt search (Linux) or brew search (macOS). For example, if ffmpeg is not found, sudo apt install ffmpeg on Ubuntu will fix it.
Fix 3: Add the Directory to Your PATH
If the program is installed but not in PATH, you can add its directory manually. The method depends on your shell and OS.
Linux/macOS (Bash or Zsh): Edit your shell configuration file (~/.bashrc, ~/.zshrc, or ~/.profile) and add a line like:
export PATH="/path/to/directory:$PATH"
Then run source ~/.bashrc (or the appropriate file) to apply the change. For example, to add Python’s user bin directory on Linux, you might add export PATH="$HOME/.local/bin:$PATH".
Windows: Open System Properties → Environment Variables. Under “User variables,” select “Path” and click Edit. Add the full path to the directory containing the executable (e.g., C:\Program Files\Python\Scripts). Click OK and restart your terminal.
Be careful not to remove existing entries when editing PATH. A common mistake is overwriting the entire variable, which can break many commands.
Fix 4: Use the Full Path or Absolute Path
If you don’t want to modify PATH, you can run the command by typing its full path. For example, if you have a program at /usr/local/bin/mytool, you can run /usr/local/bin/mytool. On Windows, you’d type C:\Tools\mytool.exe.
This is useful for one-off runs, but it’s tedious for frequent use. Adding the directory to PATH is usually better.
Common Problems and Misconceptions
“Command not found” after installing a program. This is often because the installer didn’t add the directory to PATH, or you haven’t opened a new terminal window. On Windows, environment variable changes don’t affect already-open terminals. Close and reopen your terminal.
“Command not found” in a script. Scripts run with a limited PATH, especially when called via cron or systemd. You may need to use the full path inside the script or set PATH at the top. For example, add export PATH="/usr/local/bin:$PATH".
“sudo: command not found” This happens when sudo itself is missing, which is rare but possible in minimal containers. You can’t use sudo to fix it; you need to run as root or use su.
“Command not found” for a built-in shell command. Some commands are built into the shell (like cd or alias). If you see this error for those, your shell might be corrupted or you’re using a different shell than expected. Try bash or zsh to switch.
Misconception: “Command not found” means the command doesn’t exist. It only means the shell can’t find it. The command might exist but not be in PATH, or it might be a script that needs an interpreter. For example, a Python script without a shebang line will fail with “command not found” if you try to run it directly.
Frequently Asked Questions
Why does “command not found” appear even though I installed the program?
Most likely the executable’s directory is not in your PATH, or you haven’t opened a new terminal after installation. On Windows, environment variable changes require a new terminal. On Linux/macOS, you may need to run source ~/.bashrc or log out and back in.
How do I find where a command is installed?
Use which <command> on Linux/macOS, or where <command> on Windows Command Prompt and PowerShell. If it returns nothing, the command is not in PATH. You can also search the filesystem with find / -name "<command>" 2>/dev/null (Linux/macOS) but that can be slow.
Can I run a command without adding it to PATH?
Yes, by using the full path. For example, /opt/myapp/bin/mytool. You can also create a symbolic link in a directory that is already in PATH, like sudo ln -s /opt/myapp/bin/mytool /usr/local/bin/mytool.
What is the difference between “command not found” and “permission denied”?
“Command not found” means the shell couldn’t locate the file. “Permission denied” means the file exists but you don’t have execute permission. Fix permission with chmod +x <file> on Linux/macOS.
Why does “command not found” happen in cron jobs?
Cron runs with a minimal PATH that often doesn’t include directories like /usr/local/bin. Always use the full path to commands in cron scripts, or set PATH explicitly at the top of the script.
Is there a way to see all commands available?
Type compgen -c in Bash to list all available commands. In PowerShell, use Get-Command. This can help you verify if a command exists under a slightly different name.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Campus Tech Innovation Hubs: What They Are
- Poco C51 Airtel Prepaid Locked Variant India?
- Jenkins vs GitHub Actions: Which CI/CD Fits Your Team?
- Turn Off Backup Encryption in iTunes?
- Shared VPS Hosting: Is It Better?
- Disk Defrag Pro: What It Does and Whether You Need It