When you see "command not found" in your terminal, it means the shell cannot locate the executable you tried to run. This commonly happens when a program isn't installed, isn't in your system's PATH, or you typed the command incorrectly. Fixing this involves verifying the command's existence, installing missing software, or adjusting your PATH environment variable.
What You'll Need
- Access to a terminal application (Terminal on macOS, Terminal or Console on Linux)
- User account with sudo or administrative privileges (for installing software)
- Internet connection (if downloading or installing packages)
- Basic familiarity with typing commands in the shell
Step-by-Step
- Verify the exact command you typed. Open your terminal and retype the command slowly, checking for typos. For example, if you meant to type
git statusbut typedget status, the shell will not findget. - Check if the command exists on your system by using
whichorcommand -v. Typewhich git(replacegitwith your command). If it returns a path like/usr/bin/git, the command is installed and in your PATH. If it returns nothing, proceed to the next step. - Search for the package that provides the command. On Debian/Ubuntu systems, use
apt searchorapt-cache search. For example, ifwhich dockerreturns nothing, tryapt search dockerto find the correct package name. On Fedora, usednf search; on macOS with Homebrew, usebrew search. - Install the missing package using your system's package manager. On Ubuntu/Debian, run
sudo apt install. On Fedora, usesudo dnf install. On macOS with Homebrew, runbrew install. Replacewith the actual name found in the search step. - After installation, verify the command is now available by typing
whichagain. It should return a file path. - If the command still returns "not found," check your PATH environment variable. Type
echo $PATHto see the list of directories the shell searches. Ensure the directory containing the command's executable (e.g.,/usr/local/binor/opt/homebrew/bin) is included. - If a directory is missing from PATH, add it temporarily for the current session with
export PATH="/new/directory:$PATH">. To make it permanent, add this line to your shell's startup file:~/.bashrcfor Bash,~/.zshrcfor Zsh (common on newer macOS and Linux systems), or~/.config/fish/config.fishfor Fish. After editing, reload the file withsource ~/.bashrcor open a new terminal. - Test the command again. It should now execute without the "command not found" error.
Common Mistakes
- Typing the command incorrectly due to similar-looking characters (e.g.,
ls -lvsls -Iorgit clonevsgit clon). - Assuming a command is installed because it works on another system, without verifying on the current machine.
- Installing a package but forgetting to reload the shell or open a new terminal, so the updated PATH isn't recognized.
- Adding a directory to PATH incorrectly, such as omitting the colon separator or using the wrong syntax for the shell.
- Trying to run a graphical application (like
firefox) from a terminal without a display server, which may cause confusion even if the command exists.
Tips
- Use tab completion in the terminal to avoid typos: type the first few letters of a command and press Tab to auto-complete or show options.
- If you're unsure what package provides a command, search online for "
command not found linux package" or use pkgfileon Arch Linux (pkgfile -b). - On macOS, if you installed software via Homebrew but still get "command not found," ensure
/opt/homebrew/bin(for Apple Silicon) or/usr/local/bin(for Intel) is in your PATH. - After installing a new shell (like Zsh or Fish), remember that startup files differ — update the correct one for your active shell.
- To see all available commands in your PATH, type
compgen -c(Bash) or explore directories in$PATHwithls.
Troubleshooting
If you've followed the steps above and still see "command not found:"
- Confirm you're editing the correct shell startup file. Run
echo $SHELLto see your current shell (e.g.,/bin/bash,/bin/zsh). Edit the correspondingrcfile in your home directory. - Check for typos in the PATH edit — a missing quote, extra space, or incorrect directory path will break it. Use
echo $PATHafter editing to verify the change took effect. - If you installed software via a method outside the package manager (e.g., a binary tarball), ensure you extracted it to a directory in PATH or created a symlink in
/usr/local/bin. - On some minimal Linux installations (like Docker containers or cloud instances), essential commands may be missing. Install base packages:
sudo apt install build-essential(Debian/Ubuntu) orsudo dnf groupinstall "Development Tools"(Fedora). - If the command exists but returns "Permission denied," the issue is not PATH-related — check file permissions with
ls -l /path/to/commandand fix withchmod +xif needed. - After making changes, always open a new terminal tab or window to test — this ensures you're using a fresh shell session with updated configuration.
Frequently Asked Questions
Why does a command work in one terminal tab but not another?
This usually means your shell startup file (like .bashrc) was edited after the first tab was opened. Changes to PATH or aliases only apply to new sessions. Open a new tab or run source ~/.bashrc to reload.
How do I find out what package installs a specific command?
Use your package manager's search: apt search on Ubuntu/Debian, dnf provides on Fedora, or brew search on macOS with Homebrew. On Arch, try pkgfile .
Is it safe to add directories to my PATH?
Yes, as long as you trust the software in those directories. Avoid adding unverified or world-writable directories (like /tmp) to PATH for security reasons.
What if which returns nothing but the command still runs?
This can happen if the command is a shell built-in (like cd, echo, or alias) or an alias. Use type to see if it's a built-in, alias, function, or file.
Do I need to restart my computer after fixing PATH?
No. Changes to PATH take effect in new terminal sessions immediately after you source the startup file or open a new tab/window. A full reboot is unnecessary.
Can I run a command without fixing PATH by using its full path?
Yes. If you know the full location (e.g., /usr/local/bin/node), you can run it directly: /usr/local/bin/node --version. This bypasses PATH lookup entirely.