DEV Community

Cover image for Resolving the "zsh: command not found: yarn" Error on macOS
Giwa Jossy
Giwa Jossy

Posted on

Resolving the "zsh: command not found: yarn" Error on macOS

As a new Mac user transitioning from a Windows environment, you will encounter some initial challenges while setting up your development environment. One of the primary issues I faced was running the yarn command in the terminal. Here's a step-by-step account of resolving the zsh: command not found: yarn error.

😑 Problem: zsh: command not found: yarn

After cloning my project repository and navigating into the directory, I tried running yarn to install dependencies but got the error below:

zsh: command not found: yarn
Enter fullscreen mode Exit fullscreen mode

😊 Solution

This error indicates that yarn is not installed on your system. To fix this, I used Homebrew, a package manager for macOS, to install yarn.

1) Install Homebrew (if not already installed):
Homebrew simplifies the installation of software on macOS. Open your terminal and run:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

2) Install yarn:
With Homebrew installed, you can now install yarn by running:

brew install yarn
Enter fullscreen mode Exit fullscreen mode

3) Verify yarn installation:
After the installation, verify that Yyrn is installed by running:

yarn -v
Enter fullscreen mode Exit fullscreen mode

😑 Problem: env: node: No such file or directory
While verifying yarn installation, I encountered another error:

env: node: No such file or directory
Enter fullscreen mode Exit fullscreen mode

This error indicates that yarn is installed, but it cannot find Node.js. Yarn depends on Node.js to run.

😊 Solution:
To resolve this, you need to install Node.js using Homebrew:

1) Install Node.js:

brew install node
Enter fullscreen mode Exit fullscreen mode

2) Verify both yarn and Node.js Installation as shown below.

node -v
yarn -v
Enter fullscreen mode Exit fullscreen mode

This time, the command should work without any issues, and you can proceed with installing dependencies and running your application.

Hope this helps.

Top comments (0)