How to Fix Zsh: Command Not Found Error on Mac [8 Fixes]

2024-02-02 19:50:50
23145 views, 4 min read

The “Zsh command not found” is a pretty common error on Mac since the release of Catalina macOS, and this error also incorporates Zsh: command not found: brew, Zsh command not found: pip, Zsh: command not found: python, Zsh: command not found: nvm, Zsh: command not found: npm, and Zsh: command not found: jupyter, but the good thing is that there’s no need to be frustrated. You can fix this issue easily if you know all about its causes.

In this guide, we’re explaining why this error occurs and what you can do to resolve it in a few minutes. All the solutions we’re discussing are proven and have worked almost every time.

So, without any delay, let’s start!

how to fix zsh command not found

Fix Pros Cons Risky Level Difficulty Level
Fix 1: Check the Command Spelling Quick and straightforward. Limited to fixing typos. Low Easy
Fix 2: Verify the Command Is Installed Identifies missing commands. A bit tricky Moderate Moderate
Fix 3: Check Your PATH Resolves issues related to command location. May require system-wide changes. Moderate Moderate
Fix 4: Verify the Zsh Configuration Addresses Zsh configuration issues. Requires understanding of Zsh configuration. Moderate Moderate
Fix 5: Reinstall Zsh Resets Zsh to a clean state. It’s a drastic measure High Moderate
Fix 6: Install Xcode Command Line Tools Essential for macOS users; resolves missing commands. Specific to macOS and not relevant for other systems. Moderate High
Fix 7: Set the Zsh Command Path in .zshrc Explicitly sets command paths for Zsh. Requires knowledge of essential directories. Moderate High
Fix 8: Reinstall macOS Comprehensive solution for persistent issues. Loss of data, time-consuming, and involves reinstalling the entire operating system. High Moderate

Part 1. Main Causes for Zsh: Command Not Found Error

The Zsh (Z Shell) stands out as a widely embraced command-line shell among MacOS users. It lets users customize the shell environment to suit their individual preferences and requirements.

But sometimes, you may face a "Zsh command not found" error. It usually occurs when the Zsh shell cannot locate the command or executable you are trying to run.

zsh command not found

Here are some common reasons for this error:

  • Command not installed
  • If you are trying to run a command that is not installed on your system, Zsh will not be able to find it. As a result, you will see the “Not Found” pop-up.

  • Incorrect PATH configuration
  • The PATH environment variable is a critical control that tells the shell where to look for executable files. If the directory containing the executable is not in your PATH, Zsh won't find it. Check your ~/.zshrc or system-wide configuration files for correct PATH settings.

  • Typo or Misspelling
  • In most cases, Typos or misspellings can lead to the "command not found" error. Even a single letter or a space can cause the issue. Sometimes, people also double-press the keys unintentionally, which can lead to errors.

  • Command Not in Executable Format
  • Ensure that the command you are trying to run is a valid executable file. Sometimes, scripts or binaries may not have the correct permissions. You can use the ls -l command to check the permissions of the executable file.

    Furthermore, they may be corrupted, which can lead to errors. It usually happens during the installation.

  • Command Located in a Non-Standard Directory
  • If the executable is in a non-standard directory, you should provide the full path to the command or add its directory to your PATH.

    Moreover, some commands are part of specific software packages. If the software is not installed or not included in your PATH, Zsh won't find the command.

  • Shell Configuration Issues
  • In some cases, configuration issues in your Zsh configuration files (~/.zshrc, for example) can lead to problems with locating commands. Therefore, it’s recommended to check for any errors or misconfigurations in these files.

    Moreover, if you're running a shell script directly and encountering this error, ensure that the script has the correct shebang line (e.g., #!/bin/zsh) at the beginning.

    Part 2. 8 Proven Solutions to Fix Zsh: Command Not Found Error

    You can try eight solutions to fix the “Zsh: Command Not Found” error. Note that each of these fixes doesn’t need much time. However, you must be careful, as even one incorrect step can jeopardize everything.

    Fix 1: Check the Command Spelling

    As discussed above, one common reason for the "Zsh Command Not Found" error is a simple typo. Note that the system can't find what you're looking for if you don't use the right letters. Therefore, you should always double-check the command you entered.

    zsh command not found check the command spelling

    Fix 2: Verify the Command Is Installed

    If you didn’t misspell the command, then the next thing to do is verify whether the command package is even installed or not.

    You use your system's package manager to install it. For example, on Debian/Ubuntu systems, you can use: "sudo apt-get install example-package".

    In addition, you can visit the official website of the tool or command you need and follow their installation instructions.

    Fix 3: Check Your PATH

    The PATH environment variable tells Zsh/Zrsh where to look for executable files. Therefore, you should focus on it, too, if you're facing the “Zsh: Command Not Found” error.

    Here’s what to do:

    Step 1. Start by viewing your current PATH. You can do this by typing “echo $PATH.

    Step 2. After this, locate the command. Let's assume it's in “/path/to/your/command.

    Step 3. Next, add “export PATH=$PATH:/path/to/your/command” and save it. Here’s another example of an export PATH:

    fix zsh command not found error

    Step 4. Lastly, restart your terminal or run source ~/.zshrc to apply the changes.

    Fix 4: Verify the Zsh Configuration

    Verifying the Zsh configuration can also help you fix the Command not found error. Doing this can ensure the system executes the command smoothly.

    Step 1. Open your Zsh configuration file, usually located at ~/.zshrc. You can use a text editor like Nano, vim, or gedit.

    Step 2. After this, check for PATH settings. There, Ensure that your PATH variable is correctly configured. Look for lines similar to “export PATH=/some/directory:$PATH.”

    verify the zsh configuration

    Step 3. Then, verify any custom configurations. You should check for any custom configurations that might interfere with the system's ability to find commands. You can also comment out suspicious lines (add # at the beginning) and test.

    Step 4. After this, save the changes and restart the terminal.

    Fix 5: Reinstall Zsh

    If you think the reason behind “Zsh: Command not found error” is that the Zsh is itself corrupted, then it’s better if you reinstall it. You can use the system’s package manager for this.

    Below is the image for Debian/Ubuntu and macOS with Homebrew:

    reinstall zsh

    Don’t forget to restart your Mac when you’re done.

    Fix 6: Install Xcode Command Line Tools

    Certain commands may also depend on the Xcode Command Line Tools. Installing or updating them can resolve issues related to missing commands.

    Step 1. First, install Xcode command line tools. For this, open a terminal and run the following command: “xcode-select --install.”

    Step 2. A pop-up window will appear asking if you want to install the tools. Keep following the installation prompts.

    install xcode command line tools

    Step 3. Next, wait for the installation. After this, you can retry the command.

    Fix 7: Set the Zsh Command Path in the .zshrc File

    If the above solutions fail, you can also try setting the Zsh command path in the .zshrc file. It can fix the problem by helping with the execution of the command. Just follow these steps:

    Step 1. Open your Zsh configuration file, usually located at ~/.zshrc.

    Step 2. Next, Type nano /.zshrc

    Step 3. After this, you can add your $PATH variable information.

    set zsh command path

    Step 4. Then, hit “Control + X.” After this, press Y and enter.

    Step 5. Now, save the changes and retry the command.

    Fix 8: Reinstall the MacOS

    If everything fails, you should reinstall MacOS to fix the issues. In fact, if you’re not tech-savvy and think the above solutions are too complicated, then you can try this solution as well.

    Step 1. Start by restarting your Mac and holding down Command + R until the Apple logo appears. Doing this will boot your device into Recovery Mode.

    reinstall macos

    Step 2. Navigate and choose Disk Utility from the Utilities menu. You can use Disk Utility to erase your Mac's internal disk.

    Step 3. After erasing the disk, exit Disk Utility and choose "Reinstall macOS" from the Utilities menu. Simply follow the on-screen instructions to reinstall macOS.

    reinstall macos

    Step 4. After the reinstallation, ensure that your system is up-to-date. You should also reconfigure your preferences and settings, including Zsh (if you are using it).

    Step 5. Finally, you can retry the command.

    But note that you will lose important files/data when you reinstall the MacOS. Therefore, you should also back up important files/folders before you do the solution.

    So, that’s all about how to fix the Zsh: Command Not Found error.

    Part 4. Bonus Tip: Recover Accidentally Deleted Data on Mac?

    There are higher chances that you will lose some of your files when you are reinstalling MacOS or trying any other solution. If you ever lose any data or files, then there’s no need to panic. We now have cutting-edge data recovery tools that can retrieve all the files within minutes. Out of all, the best one Mac users can use is AnyRecover.

    It’s an iMyFone data recovery software that can bring back all the deleted data with just a single click. That’s why it has received praise from leading Tech media outlets, including Engadget, PC World, Tech Radar, etc.

    AnyRecover deleted file recovery tool

    2,061,704 Downloads

    Features of AnyRecover

    • AnyRecover can restore deleted data from over 2000 storage devices, even if there’s no Time Machine backup.

    • It can retrieve files no matter how they were lost. Whether you were reinstalling macOS or simply deleted your data accidentally, this software can recover everything.

    • The scanning and recovery speed is ultra-quick. You will have all of your data back within a few minutes.

    • It uses top-tier AI to fix your corrupted files, including the ones that are causing the command issues.

    • This software supports both the latest and older MacOS versions.

    • It supports 1000+ formats, which means you won’t ever face compatibility issues (no matter for which reason you are using AnyRecover).

    How to Recover Deleted Data on Mac?

    Step 1: Download and Install AnyRecover on your Mac and launch it. From different options, choose the "Data Recovery" mode.

    go to pc hard drive recovery in anyrecover

    Step 2: Select the deleted data type and begin the scanning. When the scanning is finished, you can also preview the lost data files.

    recover mac data loss

    scan the selected location

    Step 3: Select the files you want to restore or choose All. Then, click “Recover.”

    recover deleted data on mac

    Part 5. Zsh: Command Not Found FAQs

    How Do I Resolve a Command Not Found on Mac?

    You can do many things to resolve the “Command not found” issue on Mac. The top ones are:

  • Check Typing: Ensure you've correctly spelled the command.
  • Verify Installation: Confirm the command is installed on your system.
  • Check PATH: Ensure the directory containing the command is in your PATH.
  • Update Zsh Config: Verify and update your Zsh configuration if needed.
  • Check for Updates: Ensure your system and software are up-to-date.
  • Why Does My Terminal Say Command Not Found?

    The terminal usually says “Command not Found” due to spelling mistakes and incorrect path configuration. Sometimes, the system/software also needs an update.

    Why Is Brew Command Not Found on Mac and How To Fix?

    If you face "brew: command not found" on macOS, it means Homebrew (a package manager for macOS) is not installed or is not in your PATH. To fix this:

  • Install Homebrew: Visit the Homebrew website and follow the installation instructions.
  • Update PATH: Ensure the Homebrew directory is added to your PATH. Here, you can also check and update your shell configuration file (e.g., ~/.zshrc).
  • Verify Installation: After updating PATH, retry running brew.
  • Conclusion

    All-inclusive, the "Zsh: Command Not Found error" occurs when the Zsh shell cannot locate or execute the command. Fortunately, you can fix them by verifying your command is installed, setting the command path, reinstalling the MacOS, and doing several other solutions.

    But note that you may also lose some files when you try to resolve the issue. Worry not! Whenever any file is lost or deleted, you can use AnyRecover Data Recovery Software to restore it. It can scan all the present and deleted files within a minute and retrieve them with a single click.

    The best part? It supports 1000+ file formats, which means you can bring back any file/data you want.

    anyrecover-icon

    AnyRecover Key features include:

    • AnyRecover is utterly developed to recover over 1000 different formats of photos, videos, documents and emails, etc.
    • You could also preview your data before recovering it.
    • This software is developed to recover all the data in its original form without overwriting it.
    • It is 100% safe and easy to use.

    Related Articles:

    James Crawford
    James Crawford
    (Click to rate this post) Generally rated 4.9 (122 participated)
    success

    Rated successfully!

    tips

    You have already rated this article, please do not repeat scoring!

    Time Limited Offer
    for All Products

    Days
    Hours
    Minutes
    Seconds
    Copied!
    GETBACK2COPY
    Copy the coupon code and use it at checkout
    Read guide to learn how to use coupon. Just 3 simple steps and save big!

    Not valid with other discount *

    No,thanks Use Coupon Now