How to fix the “zsh command not found” error
Developers these days already know the power of a Terminal instead of the regular GUI ( Graphical User Interface ) which the Linux environment is more focused on these days. Though it might seem very hard and challenging to use it when compared to GUI but believe me, it’s thousand times more convenient, powerful, and useful when it comes to a career as a Developer. If you want additional features which are not included by default in bash then you might want to use zsh which is also used as an Interactive login shell for Linux and Mac. Zsh which is built on top of Bash with many improvements including some features from Ksh and tcsh. After having features from all these programs it becomes a very powerful program to use. Zsh
is also known as Z shell.
But sometimes most of us might also have faced the error termed as
zsh: command not found
Code language: Bash (bash)
to which we’ll discuss the most common errors that lead to this error and their solutions.
Common Reasons for this Error
There may be multiple reasons for this error and processes to reproduce this error, but in this article, we’ll discuss the most common reasons for zsh Error.
- Not Valid Command
- The package is not Installed
- The mis-spelling of the command
- Package not on the Path
- Package not installed/available in .zshrc file
Why zsh instead of Bash??
Bash often comes pre-installed and configured in Linux Distro, It’s powerful and more than enough when you’re to use many features. But when you want to use features like Automatic CD, recursive path expansion, and others, you have to use zsh
instead of `Bash“.
Solution 1 – Check whether your command is valid or not
If any command doesn’t work, it’s the first thing that you double-check is if the command is correct or not, Most of the time users make mistakes in typing the commands.
Let’s look at an Example
If we’re trying to run a command to clear the Terminal Screen and you’re coming from Windows Background, you may write cls
instead of clear
,
So instead of getting a clear screen, you’ll get
dev-ubuntu% cls
zsh: command not found: cls
Code language: Bash (bash)
To fix this
try using a Package named thefuck
, which will correct your previous command of the console.
Solution 2 – Check if Command is not misspelled
The second most rule that a User follows if they get an command not found
error is that check the spelling of the command, Checking whether it is a valid command or not still at first.
Let’s Look at the Example
If we’re trying to run a command with a wrong spelling the Linux Terminal will not be able to identify the command, resulting in not being able to execute the command.
Let’s try to run netstat
with the spelling nestat
, which eventually will result in not being able to execute the command.
dev-ubuntu% nestat
zsh: command not found: nestat
Code language: Bash (bash)
To Fix this
Check the command for its name or use the thefuck
package to rectify the command.
Solution 3 – Make sure the Package is installed on your System
Many times it happens that due to some reason a User has to uninstall the package but still after uninstalling the package the user tries to access the command resulting in Command not found Error
Let’s take an Example
If we’re trying to access the npm
package but the package npm
is not installed on the system, or if we’re trying to access the react
package but it’s not on the path or installed at the global level, it’ll result in Command not Found* Error.
dev-ubuntu% npm
zsh: command not found: npm
Code language: Bash (bash)
To Fix this
try running the command to Install the package which you’re trying to access or hit this command
sudo apt install package-name
Solution 4 – Make sure the command is accessible and on $PATH
Most of the time it happens that the command is not on the Path, but still, the user is trying to access the Package.
For Example
If you’re trying to access the package which is not on the $PATH, it’ll result in the error of Command not Found.
dev-ubuntu% npm
zsh: command not found: npm
Code language: Bash (bash)
To Fix this
Try adding the location of the package to the $PATH
Unix users can try running this command
export "$PATH:/home/coderaman7/.local/.bash"
Code language: Bash (bash)
Solution 5 – Setup .zshrc file to export your Paths
Sometimes due to some error or mishandling, the .zshrc
the file gets deleted which will eventually result in loss of Data and the command not being able to execute, due to misconfigurations of the PATHS.
To fix this
- Create a new file at the root of your Machine named
.zshrc
- try running command
export "$PATH:/home/coderaman7/.local/.bash"
Conclusion
As discussed in this article, 5 main and common problems will cause the Error zsh: command not found
. If you’ve tried all of these and it successfully ran. The zsh error might have gone away and you’re back with your package accessible again.
Thanks for reading
Happy Hacking
Sharing is caring
Did you like what Aman wrote? Thank them for their work by sharing it on social media.