[Solved]: “zsh command not found”
Zsh (Z Shell) is a powerful shell and command-line interpreter for Unix-like operating systems. It is an alternative to the more commonly used Bash shell and offers many features and improvements over Bash.
There are several reasons for zsh, i.e., it offers advanced features such as better auto-completion, enhanced globbing, improved history management, a more modern and customizable interface compared to other shells, and much more.
If you are trying a zsh command for the first time, you will encounter the error “zsh command not found” appears. Well, that’s not an issue; we are here to get you to the reasons and the solutions to fix the stated error.
Note: This error may occur on any of the Linux systems, i.e., Debian/Ubuntu, Arch/Manjaro, etc. We will list the commands to use on all the Linux distributions. However, we have used Ubuntu 22.04 to show the practical demonstration.
How to Fix the “zsh command not found” Error on Linux?
Most of the “command not found” errors on Linux have the same origin as the “zsh command not found error.” The error “zsh command not found” typically occurs when you try to execute a command in the zsh shell that is not installed or not in the shell’s search path.
For instance, we tried to use the “zsh” command here but couldn’t. As the command is not installed on our system, the “zsh command not found” error is printed.
So, there are two possible fixes as per the error, i.e., the first is to install the command, and the second is to add its path to the shell’s environment. Let’s practically demonstrate these to you:
Solution 1: Install the zsh
The installation of the “zsh” command varies from distribution to distribution. Here, we have listed the commands to install the “zsh” utility on your system:
$ sudo apt install zsh
$ sudo pacman -S zsh
$ sudo yum install zsh
$ sudo dnf install zsh
After installing the zsh utility, now execute the following command to ensure that the bug has been fixed or not:
The successful execution of the command shows that the error has been fixed.
Solution 2: Add the zsh to the Shell’s Current Path
While using the command, your system gets the information from the executable of the command. If that path is not available even after the installation, it is recommended to do it manually by following the steps:
Step 1: Get the zsh Path
First, you need to get the path of the zsh executable (from which the zsh command gets the data at the time of execution) using the command:
$ which zsh
Remember, the “/usr/bin” is the main directory where the executables of other commands are available and is the same in the “zsh” case, which is proved in the output of the command.
Step 2: Configure the “.bashrc” File
Open this file in any editor, i.e., as we are using the nano editor:
$ sudo nano .bashrc
Once you get to know the executable of the zsh, add the following line at the end of the file:
After that, load the current shell environment by applying the source command on “.bashrc” as follows:
$ source .bashrc
Once done, you will now be able to execute the zsh command and launch the shell. Here it is. We have accessed the zsh and applied an update command shown below:
Like most basic Linux commands, the user thinks the “zsh” utility must come by default, which is not true in actuality. The “zsh command not found” error occurs if the “zsh” utility is not installed on your system or its path environment variable is not set.
To fix the “zsh command not found error,” the users must install it on their system or add the “zsh” executable to the shell’s current path. The installation commands differ as per your Linux distribution provided in this post. Finally, you have learned why the error, “zsh command not found,” and the best solutions to rectify this error.
Do not forget to subscribe at Linux-Genie and visit us for more Linux troubleshooting tips and tricks.