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

  1. 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 status but typed get status, the shell will not find get.
  2. Check if the command exists on your system by using which or command -v. Type which git (replace git with 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.
  3. Search for the package that provides the command. On Debian/Ubuntu systems, use apt search or apt-cache search. For example, if which docker returns nothing, try apt search docker to find the correct package name. On Fedora, use dnf search; on macOS with Homebrew, use brew search.
  4. Install the missing package using your system's package manager. On Ubuntu/Debian, run sudo apt install . On Fedora, use sudo dnf install . On macOS with Homebrew, run brew install . Replace with the actual name found in the search step.
  5. After installation, verify the command is now available by typing which again. It should return a file path.
  6. If the command still returns "not found," check your PATH environment variable. Type echo $PATH to see the list of directories the shell searches. Ensure the directory containing the command's executable (e.g., /usr/local/bin or /opt/homebrew/bin) is included.
  7. 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: ~/.bashrc for Bash, ~/.zshrc for Zsh (common on newer macOS and Linux systems), or ~/.config/fish/config.fish for Fish. After editing, reload the file with source ~/.bashrc or open a new terminal.
  8. 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 -l vs ls -I or git clone vs git 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 pkgfile on 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 $PATH with ls.

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 $SHELL to see your current shell (e.g., /bin/bash, /bin/zsh). Edit the corresponding rc file 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 $PATH after 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) or sudo 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/command and fix with chmod +x if 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.