If you're seeing "zsh: command not found" when trying to use a custom command in your Zsh shell, it means the system can't locate the executable for that command. This is usually a simple fix that involves either installing the missing package or correcting your shell configuration. The quickest solution is to install the tool or package that provides the command using your package manager—if you're missing a command like `ffmpeg`, `curl`, or a custom script, installing the corresponding package will resolve it.
What You'll Need
- The package manager for your system (e.g., `brew`, `apt`, `dnf`, or `pacman` depending on OS)
- Admin or sudo privileges to install packages (or your user's package manager credentials if configured)
- A working internet connection to download the package
- If the command is a custom script, the full path to its source file
Step-by-Step
-
Check if the command exists in your PATH. Run this command to verify where the shell looks for executables:
echo $PATHIf your command isn't listed in the output, it means the shell can't find the executable. Next, find where it *should* be installed. -
Search for the package that provides your missing command.
The command's name might not directly match the package name. Use your package manager to find the correct package:
- Homebrew (macOS/Linux): Run
brew search(e.g.,brew search ffmpeg) - APT (Debian/Ubuntu): Run
apt searchorapt-file list - DNFLinux/DNF (Fedora/RHEL): Run
dnf provides - Pacman (Arch Linux): Run
pacman -Qn | grep
gitto find the package name (usuallygititself). - Homebrew (macOS/Linux): Run
-
Install the package using your package manager.
Once you have the package name, install it with:
brew install(Homebrew)apt install(APT)dnf install(DNFLinux/DNF)pacman -S(Pacman)
nmapis installed asnmapbut you might havenet-toolsfor `netstat`), install the correct one. -
Verify the command works. After installation, test if the command is now found by typing it directly or running:
whichIf it returns a path (e.g.,/usr/local/bin/git), the command is available. If not, proceed to the next step. -
If the command is custom (e.g., a script), add its path to your
PATH. If you created or downloaded a script (e.g.,/home/user/my_script.sh) and it’s not in yourPATH, add its directory to your shell's environment variable:- Open your shell configuration file (e.g.,
~/.zshrc,~/.bashrc, or~/.config/fish/config.fish—useecho $SHELLto find it). - Add this line to append the script's directory to
PATH:export PATH="$PATH:/path/to/script/directory"(Replace/path/to/script/directorywith the actual path, e.g.,/home/user/scripts.) - Save the file and reload your shell:
source ~/.zshrc(or the correct config file for your shell).
- Open your shell configuration file (e.g.,
If That Did Not Work
Try these additional steps:-
Check for typos in the command name. Run:
typeThis tells you if the command exists but has a different name (e.g.,type gitmight returngit is aliased to git ls-files --ignored --). -
Search for the executable directly. Use a file search tool like:
find / -type f -name "*(Replace*"> *with the command name. This may take a few minutes and shows all files matching the name. If the executable is in a non-standard location, you’ll need to add that path to* PATH.) -
Ensure the script is executable. If you’re using a custom script, make sure it has the correct permissions:
chmod +x /path/to/script.shThen add its directory toPATHas shown above. -
Reinstall the package. If the package was installed incorrectly, uninstall it and reinstall:
brew uninstall# Homebrew apt removeThen reinstall it.# APT -
Restart your terminal or shell. Sometimes, changes to
PATHor shell config files require a terminal restart to take effect.
Common Mistakes
-
Using the wrong package. The package name for
curlis sometimeslibcurlorcurl, depending on your system. Runwhich curlto check which package installed it. -
Missing dependencies. If you installed a package but the command still isn’t found, it might require dependencies. On Homebrew, run:
brew install(APT/DNF/Pacman do this automatically, but check if the package provides a flag like--with-deps -devfor library files.) -
Not updating your shell config. If you added a path to
PATHbut didn’t reload your shell, changes won’t take effect until you restart or runsource ~/.zshrc. -
Running the command incorrectly. If you used
./script.shinstead ofscript.sh, the shell won’t find it even if it’s inPATH. Always run the name as it appears in thePATH. -
Permissions issues. If you’re running a script as another user (e.g., via sudo), ensure the script has execute permissions for all users:
chmod +x /path/to/script.sh(If it’s owned by root, you may need sudo to run it.)
Tips
-
Use
typeandwhichto troubleshoot.typetells you if the command is a built-in, alias, or executable.whichshows the full path to the executable. If neither works, the command is either missing or misconfigured. -
Avoid overwriting system tools. If you’re installing packages from source or modifying scripts, ensure you don’t replace system executables (e.g.,
/usr/bin/pythonvs./usr/local/bin/python). Usewhich pythonto check the correct path. -
Check for syntax errors in custom scripts. If you created a script, run a shell checker like
shellcheck(install via Homebrew:brew install shellcheck) to find errors before running it. -
Use aliases for frequently used commands. If you frequently need a command that’s not installed, add an alias to your shell config (e.g.,
alias myalias="command") instead of manually installing it. -
Update your system regularly. Outdated packages can cause compatibility issues. Run:
brew update && brew upgrade # Homebrewapt update && apt upgrade # APTdnf upgrade # DNFto keep your tools up-to-date.
Troubleshooting
-
The command exists but isn’t found.
Run
find / -name "*to locate the executable. If it’s in a non-standard location (e.g.,* 2>/dev/null /opt/local/bin), add that path toPATH:export PATH="$PATH:/opt/local/bin"Then reload your shell. -
I installed the package but the command still isn’t found.
Check which package installed it:
which|| dpkg -L # APT brew whichIf the executable isn’t listed, the package might not have been installed correctly. Reinstall the package.# Homebrew -
I’m missing system dependencies.
For Homebrew packages, use:
brew install --with-depsFor APT/DNF/Pacman, check if the package includes a-devflag:apt installIf you’re unsure, search for the package’s documentation online.-dev -
I’m using a custom script and it still fails.
Run
ls -la /path/to/script.shto check for execution permissions. If the script is in a non-standard location (e.g.,~/.local/bin), ensure~/.local/binis in yourPATH:mkdir -p ~/.local/bin && export PATH="$HOME/.local/bin:$PATH"Then reload your shell. -
My shell won’t load changes.
If you added a path or alias to your shell config, restart your terminal or run:
exec zsh(orsource ~/.zshrcif your shell supports it). -
The command is a built-in or alias but not recognized.
Verify with
type. If it’s an alias, edit your shell config (e.g.,~/.zshrc) and remove or correct the alias:unaliasoraliasThen reload your shell.="correct-command"
Frequently Asked Questions
Why does "zsh: command not found" happen?
This error occurs because the shell (Zsh) cannot locate the executable for the command you’re trying to run. This happens if the command is missing, misnamed, or not in your PATH environment variable.
How do I permanently fix this?
Install the correct package for the command, add its directory to PATH (if it’s a custom script), or create an alias in your shell config. Always check with which or type before proceeding.
What if I don’t know the package name for the command?
Use your package manager’s search tool (e.g., brew search, apt search) or search online for the command’s package name. For example, if you want ffmpeg, search for ffmpeg to find the correct package.
Why can’t I find my command in PATH?
The command might be in a non-standard location (e.g., /usr/local/bin or a user-specific directory like ~/.local/bin). Run find / -name "* to locate it, then add its directory to PATH.
How do I add a script to my PATH?
Add a line to your shell config (e.g., ~/.zshrc) like:
export PATH="$PATH:/path/to/script/directory"
Then reload your shell with source ~/.zshrc. Ensure the script has execute permissions with chmod +x /path/to/script.sh.
What should I do if I installed the package but the command still doesn’t work?
Check which package installed it:
which
brew which
If the executable isn’t found, reinstall the package or check for missing dependencies.