5 Solutions – How to Fix “Zsh command not found” error in Linux or macOS

I have seen many people face this “zsh command not found” error while using Unix, Linux or macOS. Also, they keep wondering on many forum websites to get the solution to this problem. So I have decided to provide all the possible fixes for this error. The most common reason for this zsh: command not found errors are –

  • The command you are executing is not valid
  • The command is valid but the package is not installed
  • Misspelt command
  • You have not given the package command in the $PATH environment
  • The command path is not set up in the .zshrc file

Below mentioned are the errors, you can get if you use zsh (Z shell) in Unix, Linux or Mac OS –

I will let you know how to fix the above-mentioned errors one by one. It doesn’t matter, what type of “zsh: command not found” error you are getting, you need to follow the below-mentioned solutions one by one to fix it.

Why “zsh” instead of “bash” shell

People are habitual of using “bash” (Bourne again shell), which is installed by default in any Linux distro. But if you want to use features like Automatic CD, recursive path expansion, spelling correction, plugins and theme correction, then zsh is the winner.

If you want to install a package of zsh in Ubuntu 21.04 from the repository, type the following command.

$ sudo apt install zsh
install zsh with "sudo apt install zsh command"

Troubleshooting articles, you may find useful

Solution1- Check whether “command is valid” to avoid zsh command not found error

Here is the golden rule, if you are getting the error “command not found” in Linux, Unix or macOS, then Validate the command first. Make sure you are running the correct command.

For example, if will try to run the “cls” command, I am getting an error.

dev-ubuntu-2104% cls
zsh: command not found: cls

Because the command to clean the screen in Linux is clear not cls, that’s why we got the error. So always make sure the command you are running is correct.

zsh command not found error

Solution2- Make sure “command is not misspelt”, if you are getting zsh command not found error

The second basic rule is to check the spelling of the command is correct or not. At least in my case, I make typo mistakes many times that result in the “zsh command not found” error.

Let me show you an example-

I was trying to run the “netstat” command but made a typo mistake and typed “nestat“, which resulted in a command not found error.

So always check for command’s spelling to fix issues around the “zsh: command not found error

check command is not misspelled to fix zsh command not found

Solution3- Make sure “package is installed”, to fix the zsh command not found error

Many times, it happens that you are trying to run a command and the relevant package is not installed. So if your command is valid and the spelling is correct, then you must check whether the required package is installed?

For example, if I try to run the command “npm” in Ubuntu, I am getting an error as follows-

dev-ubuntu-2104% npm
zsh: command not found: npm
zsh: command not found: npm

Because “npm package is not installed in my Ubuntu 21.04“. If I will install the npm package in Ubuntu, I will not get the error.

dev-ubuntu-2104% sudo apt install npm

Solution4- Check “$PATH” Environment variable is correctly set to fix the “zsh: command not found error

If you have the package installed and still you are getting the “zsh: command not found error“. It means you have to set up a PATH variable for your command package or you did mess up with the existing one.

Although most of the packages, automatically set up the path variable during installation. Sometimes in the case of custom installation, you may need to set up path variables manually in Linux or macOS.

In this example, I have installed the maven package, but am still not able to run the “mvn” command.

dev-ubuntu-2104% mvn
zsh: command not found: mvn
command not found error for mvn, if maven package variable is not setup properly

Because $PATH in Linux or Environment variable in Windows needs to setup. Maven is a custom installation and the path needs to include according to your installation directory.

For Linux, run the following command. In my case, my maven commands are in “/opt/apache-maven-3.6.0/bin”. You can replace it with yours.

dev-ubuntu-2104% export PATH=$PATH:/opt/apache-maven-3.6.0/bin

For Windows add the path of the maven bin directory to the system variable path.

For example, I have added “C:\Program Files (x86)\Apache Software Foundation\apache-maven-3.6.0\bin to my system path variables.

Make sure the path is correct, otherwise you will get the “zsh: command not found” error again while running mvn command.

Solution5- Setup the command path in the .zshrc file to fix the “zsh: command not found error

If you have installed the package and set up the path variable, still when you exit and re-login to the terminal, you are getting a “zsh command not found” error. It means you need to set up the command path in the “.zshrc” file to make it permanent.

If the .zshrc file doesn’t exist, you can create one with the “touch ~/.zshrc” command.

So whenever you exist and reopen the terminal, your .zshrc file will execute and set up the command path. Follow these steps to edit the .zshrc file.

  1. Open Terminal on Linux or macOS,
  2. Validate you are on Zsh Shell, if not then type zsh and press “Enter“.
  3. Now type nano ~/.zshrc
  4. Now add your $PATH variable details: Example: export PATH=”$PATH:/opt/apache-maven-3.6.0/bin/”
  5. Press Control + X, followed by Y to save the file, press enter to exit Nano editor,
  6. Now type command source ~/.zshrc to commit changes

I am sure, if you will follow above mentioned 5 solutions, you will definitely get rid of the “zsh command not found error”.

FAQ – zsh: command not found error

How do I fix the “zsh: command not found brew” error on macOS

Make sure you have installed the brew right and the path variable is set up correctly.
Step1 – Open a terminal and make sure, you are on the zsh prompt. If not then type zsh and press enter.
Step2 – Run the following command to install brew
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
Step3 – Set path variable using the following command as also suggested as the next step in the wizard
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.zprofile
Step4 – Run the following command and press enter
eval $(/opt/homebrew/bin/brew shellenv)
Step5- Run the brew help command to validate the installation.

In case you have installed brew already and it’s not working, then add the following command to the ~/.zshrc file.
export PATH=/opt/homebrew/bin:$PATH
Then run the source command to implement changes.
% source ~/.zshrc

How do I fix the “zsh command not found conda” error

Make sure you have the anaconda package installed on your system. Then follow these steps-

Step1– Open .zshrc file
% vim ~/.zshrc
Step2– Just add source ~/.bash_profile into .zshrc file
Step3– save and exit terminal
Step4- Run the
following command to implement changes
% source ~/.bashrc
% source ~/.zshrc

How to fix the “zsh command not found code” error in macOS

Make sure you have installed the visual studio code as per the instructions provided here. If you are getting this error during launching code, make sure you follow these steps-

-> If you are using the bash shell, copy and paste the following command on the terminal.

cat << EOF >> ~/.bash_profile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin" EOF

-> For macOS users, where zsh is the default shell, follow this command

cat << EOF >> ~/.zprofile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin" EOF

How do I fix the “zsh command not found MySQL” error

This issue happened due to the path is not being set up correctly after MySQL installation on mac OS. Follow these steps-

Step1- Edit .zshrc file
% vi ~/.zshrc

Step2- Locate for “export PATH” entry and append “:/usr/local/mysql/bin” to the end of the line. If the export PATH entry doesn’t exist, then add the following command

export PATH=${PATH}:/usr/local/mysql/bin/

Step3– Run source ~/.zshrc

Step4– Restart terminal

How do I solve the “zsh command not found docker” error on macOS

This issue generally occurs due to not following the right instructions during docker installation. Make sure you follow the instructions provided on the docker.com website to install docker on macOS


As explained in this tutorial, If you have followed the correct installation instructions and set up the path variable correctly in your system during the installation of any package either in Linux or macOS. You will not get an error of the “zsh command not found“.

If you are still facing this error, just follow solutions 1-5 provided in this post. I am sure it will help you to get rid of this error.

Let me know if you still face any issues via your comments and I will try to help you.


I'm Dev, your friendly neighbourhood Tech Savy. I spend my days with gadgets, servers, and the occasional laugh-inducing software mishap. Think of me as your tech-savvy, glitch-prone buddy. If you've got questions, feedback, or just need someone to blame when your Wi-Fi goes haywire, I'm your guy!