What the "command not found" error means
The command not found error (in Russian: "команда не найдена") occurs when the macOS operating system cannot locate an executable file for the command you are trying to run in the terminal. It usually looks like this:
zsh: command not found: git
or
bash: git: command not found
This error means the system checked all directories listed in the PATH environment variable but did not find an executable file with the specified name in them. It can appear when trying to run any command—from standard utilities (git, python, node) to your own scripts.
Common causes
- The command is not installed. The most common reason is that the required software (e.g., Git, Python, Node.js) is simply not installed on the system.
- The command is not in
PATH. The executable file exists, but the directory where it is located is not included in thePATHvariable. This often happens with programs installed manually (e.g., in/usr/local/binor~/bin). - Spelling error in the command. A simple typo or using the wrong character case (although macOS is usually case-insensitive, some utilities may not be).
- Shell configuration issues. Configuration files (
~/.zshrc,~/.bash_profile,~/.profile) are corrupted or contain errors, causingPATHnot to be set correctly. - The command is installed, but the path is not exported. Some installers (e.g., via
pip install --user) place binaries in~/.local/binbut do not add this path toPATHautomatically.
Method 1: Check the command spelling
Before diving deeper, make sure you haven't made a typo. macOS is sensitive to spaces and special characters. Also, verify that the command actually exists using the type or which utilities:
type git
If the command is not found, you will see the same error. If it is found, you will learn its full path and type (alias, function, executable file).
Method 2: Install the missing command
If the command is not installed, install it. The recommended method for macOS is the Homebrew package manager:
- If Homebrew is not installed, install it according to the official instructions.
- Install the needed package. For example, for Git:
brew install git - After installation, the command should be immediately available. If not—proceed to Method 3.
For some utilities (e.g., python3), you can use official installers from the developer's website or pip (for Python packages).
Method 3: Check and configure the PATH variable
The PATH variable is a list of directories where the system searches for executable files. Check its current value:
echo $PATH
The output will look similar to:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
How to add a directory to PATH
If you know where the executable file is located (e.g., which git returned /usr/local/bin/git), and that directory is not in PATH, add it:
- Determine which shell you are using:
echo $SHELL/bin/zsh— zsh (default since macOS Catalina)/bin/bash— bash
- Open the corresponding configuration file in a text editor (e.g.,
nanoorvim):- For zsh:
nano ~/.zshrc - For bash:
nano ~/.bash_profileor~/.profile
- For zsh:
- At the end of the file, add a line (replace
/your/pathwith the needed one):export PATH="/your/path:$PATH"
Important: The:$PATHat the end preserves existing paths. - Save the file (Ctrl+O, Enter) and close the editor (Ctrl+X).
- Apply the changes without restarting the terminal:
source ~/.zshrc # for zsh # or source ~/.bash_profile # for bash - Verify the path was added:
echo $PATH
Method 4: Restart the shell or terminal
Sometimes changes in configuration files are not automatically applied to the current terminal session. After editing ~/.zshrc or ~/.bash_profile, run:
exec $SHELL
This command restarts the current shell, loading the updated settings. Alternatively, simply close the terminal window and open a new one.
Method 5: Reinstall the problematic command
If the command is installed but the executable is corrupted or has incorrect permissions, reinstall it:
- Via Homebrew:
brew reinstall <package>
For example:brew reinstall git. - Via pip (for Python packages):
pip install --user --upgrade --force-reinstall <package> - System utilities (e.g.,
ls,cp) usually do not require reinstallation. If they are broken, you may need to restore the system or reinstall macOS.
Prevention
To avoid the command not found error in the future:
- Use Homebrew to install CLI utilities. It automatically manages paths and dependencies.
- Regularly check your
PATH. Ensure it includes standard system paths (/usr/bin,/bin,/usr/sbin,/sbin) and paths to programs you install (/usr/local/bin,~/.local/bin). - Do not manually delete files from
/usr/local/binor other system directories. This can break links. - For language-specific packages (Python, Node.js) use virtual environments (
venv,nvm) to isolate dependencies and manage paths. - Before running a command, check its availability via
whichortype, especially if you are entering it for the first time.
Following these recommendations will ensure stable terminal operation and help you avoid most command-location issues.