How to fix the "zsh command not found" error

How to fix the "zsh command not found" error

In this article, I'll tell you about how to resolve the Error How to fix the "zsh command not found" error.

ยท

5 min read

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 believe me, it's a 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 too. 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

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 this 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

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 important rule that a User follows if they get a command not found error is to check the spelling of the command, Checking whether it is a valid command or not 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

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 a 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

To Fix this

try running the command to Install the package that 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 that is not on the $PATH, it'll result in the error of Command not Found.

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

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"

Solution 5 - Setup .zshrc file to export your Paths

Sometimes due to some error or mishandling, the .zshrc 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 .zshrctry by running the 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 Error might have gone away and you're back with your package accessible again.

This article was originally written back when I was starting but as a private article, I was afraid of building in Public but now Let's do this.

So my Web App which I am rebuilding is available on justaman045.vercel.app you can visit it now also but it's currently under heavy maintenance and the look and feel will change in about 2 or 3 weeks.

Promotion

Currently, I am also focused on building the Community mentioned below:

  1. Anime Community:- Instagram/lethal_astra

Also, it'll be helpful if you can just follow this link to Medium and give me a like and follow there too.

Contact

To contact you can join my Discord Server where I intend to keep the community in one place and also serve the community
Discord Link:- https://discord.gg/ZfAKPZvT ( It's brand new and I'm okay if you help me out on setting up this ).

Thanks for Reading
Happy Hacking

ย