Sometimes, when you try to use commands in the Terminal on a Mac, you might get an error message that says command not found.
Starting with macOS Catalina, Apple changed the main system used in the Terminal from ‘bash’ to ‘zsh.’ One of the most common reasons behind this is that the shell cannot find the command that you are trying to execute.
So, if your Mac is running macOS Catalina or a newer version, you might see an error like “zsh: command not found: brew.”
Let us fix Zsh command not found error in the following manner through the terminal and other methods.
Table Of Contents
- How to Fix Zsh Command Not Found Error?
Common reasons for Zsh command not found error
- The command is not spelled correctly, resulting in an error.
- Incorrect PATH variable for executing the Zsh(Z shell) command.
- The correct package is not installed.
- Recent incorrect configuration for the Zsh command.
How to Fix Zsh Command Not Found Error?
1. Check the Syntax
It is common to get a command not found error because of misspellings or typos. You get it when typing things manually, and unintended characters get typed.
You should double-check the command to see any errors. We would recommend copying the command directly into the terminal instead of
2. Set $Path environment in .zshrc file
A path in a file system points to a specific location. In the same way, for Terminal commands, the PATH system variable ($PATH) shows the directories where executable programs are stored.
Because of $PATH, your Mac can easily locate these files when you execute a command, letting you to use just the command’s name, such as ‘ls’, instead of its complete path.
Therefore, you must set the $PATH before moving forward so that you don’t get the command not found error.
1. Press Command + Spacebar to open the Spotlight search
2. Search and head to the terminal.
3. Paste the following command and press enter.
This will fix the zsh command not found error on macOS.
3. Make sure the package is installed
You can get a command not found error when a package is not installed while you are trying to access it. Here is how you check if the package is installed.
1. Enter the following command and press enter to list all the installed packages.
For Python Packages
1. If you want to see installed Python packages, then enter the following command and press enter.
4. Create Zsh Profile
Command not found error can occur in Zsh if the .zshrc file is not created or if it is missing certain configurations. Here is how you create a Zsh profile before entering other commands.
1. Enter the following command in the terminal and press enter for redirecting to the home directory.
2. After that, enter the following command to create a Zsh profile.
3. Now, let us check Zsh profile by opening it.
4. You will see zshrc file open in the text editor, confirming the creation of the Zsh profile.
5. Reinstall/Restore Mac
When you have exhausted all options to fix the command not found error, then it is time to start fresh. Reinstalling macOS can be a solution for fixing the Zsh command not found error.
Especially if the error is due to a broader system issue, such as corrupted system files or misconfigured settings, you can use Apple’s official guide on reinstalling macOS.
And if you have backed up macOS using Time Machine, then you can restore it back to a computer started when you did not get the Zsh command error. For this as well, you can use the official guide on restoring macOS through Time Machine.
How Do I Switch to Zsh Commands on Mac?
For macOS Catalina and later versions, Zsh should already be set as your default shell. Here is how to confirm or switch to it:
Check Current Shell:
In the Terminal, check your current shell by typing echo $SHELL. If it returns something like /bin/zsh, then Zsh is already your default shell.
Change to Zsh (if needed):
Enter the command chsh -s /bin/zsh in the Terminal. You might need to enter your password to confirm this change.
Finally, close and reopen your Terminal. This starts a new session using Zsh.
Solve Command Not Found error on maCOS
So, here is how you can fix command not found error on macOS. Using package managers like HomeBrew or Macport, along with Zsh, can make things easier.
Make sure to type the correct commands to resolve the errors.