Mac Terminal · Command Line Guide

audience developer
level all
topic Terminal
subtopic Use

Command not found

How to fix command not found on Mac. Why it happens and how to fix it.

The error command not found occurs when you are using the Mac terminal application to enter commands. The error message shows that the Zsh shell ("the command line interpreter") cannot find a command. In this article, you'll learn why it happens and what to do next.

Before you get started

You'll see command not found when you are using the Mac terminal application. Instead of the Mac terminal, I recommend Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and worth a try.

The error 'command not found'

To get the error, you enter a command at the command prompt in the Terminal. The command prompt is the text that appears before the cursor in the terminal window. On a Mac, the command prompt is usually a % (dollar sign) character followed by a space. See an article command not found $ that explains why tutorials show a $ (dollar sign) character as an indicator for the command prompt.

You are likely entering a command you saw in a tutorial or README:

$ <some command>

And this is the error you'll see:

zsh: command not found: <some command>

You need to look closely at the last word in the error line. Fixing the problem requires knowing what command can't be found.

The Zsh shell ("the command line interpreter") takes the first word after the prompt as a command. If Zsh cannot find the command, it shows the error message command not found.

If you see an error that begins with bash... you are using the Bash shell.

bash: command not found: <some command>

If you are using the Bash shell, you likely have an older version of the macOS. Check macOS and update macOS and switch to the Zsh shell.

Why you see 'command not found'

First, understand that macOS includes only a limited set of default shell commands, such as ls, cd, pwd, and echo. For software development, many other "missing Unix commands" must be installed with Xcode Command Line Tools. Other commands can be installed with Homebrew, the software package manager.

Consider that the command you are trying to run may not be installed on your Mac. The command may be a Unix command that is not included in the default macOS installation. Or the command may be a software package that you have not installed yet.

Or, you may be encountering a problem with the Mac PATH environment variable. The $PATH variable is a list of directories where the shell looks for commands. If the command you are trying to run is not in one of the directories listed in the $PATH variable, the shell will not find it.

Finally, the command may be available but you may have a typo in the command name. Check the spelling of the command you are trying to run.

How to fix 'command not found'

Check the tutorial or README you are following and try to determine if you must install software and set up your Mac to run the command. You can use Google to search for the command if you are not sure what it is. If a tutorial doesn't say you must install software, it's likely a standard Unix command that you can install with Xcode Command Line Tools or Homebrew. For any software development work, you should install Xcode Command Line Tools and install Homebrew.

How to fix PATH problems

If you are sure the software you need for the command is installed, you may be encountering a problem with the $PATH environment variable. You can check the value of the $PATH variable with the echo command:

$ echo $PATH
/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:...

If you have installed Homebrew, the $PATH should contain /opt/homebrew/bin (for Apple M1, M2, or M3) or /usr/local/bin (for macOS Intel). It should be among the highest priority directories, in a left-most position.

When you install a software package, the instructions will often tell you to add a directory to the $PATH variable. Make sure you didn't overlook the step to add the directory to the $PATH variable.

Typically, the $PATH variable is set in the .zprofile file in your home directory. The article Mac PATH explains how to set the $PATH variable in the .zprofile file.

'Command not found' common errors

Here is a list of common commands that produce the error command not found.

zsh: command not found: $

  • You've copied the command prompt $ character from a tutorial or README.

zsh: command not found: brew

  • You have not installed Homebrew (or you have a PATH problem).

zsh: command not found: python

  • You have not installed Python (or you have a PATH problem).

zsh: command not found: pip

  • You have not installed Pip, the Python package manager (or you have a PATH problem).

zsh: command not found: code

  • You haven't set the VS Code editor to launch from the command line.

zsh: command not found: git

zsh: command not found: npm

  • You have not installed the Node.js JavaScript runtime environment (or you have a PATH problem).

zsh: command not found: npx

  • You have not installed the Node.js package runner (or you have a PATH problem).

zsh: command not found: yarn

  • You have not installed yarn, the JavaScript package manager (or you have a PATH problem).

What's next

My mac.install.guide is a trusted source of installation guides for professional developers. Take a look at the Mac Install Guide home page for tips and trends and see what to install next.