If you face the error “zsh: command not found” there might be a variety of reasons, which rely upon the spelling, authenticity, and availability of the package.
In this post, you will find out more about the problems like zsh: command not found: brew, zsh: command not found: pip, and zsh: command not found: python.
If you have completed a system update in your macOS Catalina, you may not be able to access a few zsh commands.
In higher versions of macOS, like Monterey, Big Sur, Ventura, etc., you could encounter an error, “zsh command not found” as well as other similar difficulties, which we shall cover in this post.
What Is the ‘ZSH’ Command?
Zsh is a login shell of MacOS. After the Catalina update was made available in 2019, macOS moved from bash to zsh.
Zsh (also known as Z shell) is simply a Unix shell that replaced bash, which was a macOS default shell.
Furthermore, choosing zsh over bash is a superior option since it will be easier for you to deal with themes, plugins, and other configurations.
ZSH Command Not Found Error: Main Reasons
“Zsh: command not found” is a typical problem that many macOS, Unix, and Linux users commonly confront.
They continue to hunt for a solution to this problem on numerous coding-related platforms.
Hence, we have decided to offer you some handy ideas which might be truly valuable for you.
However, you will need to understand the reasons for this mistake. The following are some of them:
1. On MacOS, the ZSH command is spelled incorrectly
Many individuals make the mistake of spelling the zsh command incorrectly when using it for the first time in macOS.
They might also mistakenly introduce an extra symbol, which will make the command invalid. macOS cannot read a command which is improperly spelled.
Hence, if you wrote it wrongly, you will get the message, “However, if your command and its spelling are fully correct,
The next step is to check for the presence or absence of the package containing the zsh command: command not found.
2. Package Not Installed
If the package consisting of the zsh command is not installed on the system, then after you input the command, it will show the error “zsh: command not found”.
But even if your command and spelling are perfect, you still need to check to see if the package that contains the zsh command is present.
3. Changing the Default Environment Configuration
You already know that with new updates supplied by macOS, your system’s macOS version updates itself. This leads to the variation of the default environment.
In certain environments, macOS supports the bash command of Linux and not the zsh command of Unix.
The zsh command does not read the variable in the same environment if the address is from the address previously supplied.
Fixing “ZSH: Command Not Found: Python”
This problem is typical whenever you try to execute python through the macOS terminal. Furthermore, native python support is not present in macOS 12.3 and higher.
Here are numerous methods to fixing the issue:
1. Install Python with the brew command. Type “brew install Python” on the terminal. Try running Python again after installing it. Repeat step 2 if the issue reappears.
2. Add Python to the zsh package folder. You can carry out this task by using the following command:
echo “alias python=/usr/bin/python3” >> ~/.zshrc
3. Restart the terminal after you have accomplished the following procedures.
Fixing “ZSH: Command Not Found”:
1. You must look at the syntax of the command thoroughly before you use it on your terminal.
The best alternative for you will be to copy the syntax from a trusted source and paste it into the terminal.
Additionally, you may contrast this command with other situations where the same command was used by others.
2. Verify that your system has the zsh command package installed.
In addition, the command is valid, and even then, the terminal is giving the “zsh command not found” problem, then the package might not be installed.
Make sure the package is completely installed on your macOS system.
3. You can also set the $PATH environment. You will need to check that this environment is correctly configured.
After installing the package, if the issue “zsh: command not found” persists, you might need to create a PATH variable to make sure your command package works as intended.
However, in most circumstances, with most macOS updates, packages automatically set path variables.
4. After you have installed the package and restarted the macOS terminal and still encounter the problem “zsh: command not found”, you will need to take the .zshrc file and configure the command path.
The .zshrc file can be edited as follows:
Step 1: Open the terminal and type zsh. Press Enter. regardless or not you use the zsh shell.
Step 2: Type nano/.zshrc in the window.
Step 3: Next, try adding the details of your $PATH variable.
Step 4: click control+ X, Y to save the file, then click Enter. The Nano editor will get closed.
Step 5: To make the changes now, try issuing the command source / .zshrc.
Summing Up
I hope that the solutions mentioned above can assist you in resolving the “zsh command not found” error.
The problem is primarily developed owing to the discrepancies between the zsh shell and the bash shell.
As macOS came up with multiple versions and upgrades, all of them did not comprise of the package containing the zsh shell.
If you have the similar difficulty on your macOS terminal, you can attempt the solutions suggested above to start working with the zsh command.
Furthermore, if Python does not execute on the terminal through zsh, you can apply the proper solution as suggested in this post.