macOSMedium

Command Not Found

[object Object]

5-10 minutes
Easy
FixPedia Team
Применимо к:macOS Sonoma 14macOS Ventura 13macOS Monterey 12zshbash

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

  1. 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.
  2. The command is not in PATH. The executable file exists, but the directory where it is located is not included in the PATH variable. This often happens with programs installed manually (e.g., in /usr/local/bin or ~/bin).
  3. 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).
  4. Shell configuration issues. Configuration files (~/.zshrc, ~/.bash_profile, ~/.profile) are corrupted or contain errors, causing PATH not to be set correctly.
  5. The command is installed, but the path is not exported. Some installers (e.g., via pip install --user) place binaries in ~/.local/bin but do not add this path to PATH automatically.

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:

  1. If Homebrew is not installed, install it according to the official instructions.
  2. Install the needed package. For example, for Git:
    brew install git
    
  3. 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:

  1. Determine which shell you are using:
    echo $SHELL
    
    • /bin/zsh — zsh (default since macOS Catalina)
    • /bin/bash — bash
  2. Open the corresponding configuration file in a text editor (e.g., nano or vim):
    • For zsh: nano ~/.zshrc
    • For bash: nano ~/.bash_profile or ~/.profile
  3. At the end of the file, add a line (replace /your/path with the needed one):
    export PATH="/your/path:$PATH"
    

    Important: The :$PATH at the end preserves existing paths.
  4. Save the file (Ctrl+O, Enter) and close the editor (Ctrl+X).
  5. Apply the changes without restarting the terminal:
    source ~/.zshrc   # for zsh
    # or
    source ~/.bash_profile   # for bash
    
  6. 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:

  1. Use Homebrew to install CLI utilities. It automatically manages paths and dependencies.
  2. 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).
  3. Do not manually delete files from /usr/local/bin or other system directories. This can break links.
  4. For language-specific packages (Python, Node.js) use virtual environments (venv, nvm) to isolate dependencies and manage paths.
  5. Before running a command, check its availability via which or type, 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.

F.A.Q.

Why does the 'command not found' error occur in macOS?
How to check if a command is added to PATH?
What to do if the command is installed but still not working?
How to add a new path to the PATH variable permanently?

Hints

Check the command spelling
Install the missing command
Configure the PATH variable
Reload the shell or terminal
Reinstall the problematic command
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community