[Fix] bash: yarn: command not found

bash: yarn: command not found” is a general error message you may encounter while using the yarn command in Linux. In this article, we will dip dive into the details and how you can resolve this “command not found yarn” error message.

bash: yarn: command not found

Before jumping into the solution, let’s understand what is yarn and the reason behind this error.

What is Yarn?

Yarn is a javascript package manager for your project be it javascript or react. You can use others’ code or share your project/components/snippets with other developers using the yarn package manager. It’s one of the most popular, secure, and reliable tools available to manage javascript code.

If you are facing a “yarn: command not found” error message then this post will walk you through the steps to get rid of the error.

Steps to fix “yarn: command not found”:

Step1: Check if yarn is installed on your computer

You first must check whether you have installed the yarn package manager in your project or on your computer. If you have not installed yarn package manager and tried to use the yarn command then it’s expected to get the yarn command not found error message as this function is not available to your project.

While there are multiple ways to install the yarn package manager, you can use these simple ways to install yarn.

i. Install the executables directly on your computer:

  1. Download yarn exe from the official website.
  2. After installing yarn executable, update the PATH environment variable.
    e.g. if you have installed yarn in Program Files, then add C:\Program Files (x86)\Yarn\bin to the PATH environment variable under the ‘System Variables‘ section.
    Note: After installing yarn, you will still get “yarn: command not found” error if the PATH is not added.

ii. Install through Node.js using npm

The recommended way of installing yarn is through Node.js as it is platform-independent. The yarn package is bundled in the Node.js setup and can be installed easily via npm (node package manager).

  1. Install Node.js if not installed already.
  2. Open command prompt or terminal.
  3. Execute the below command.
    Note: Use –global command in order to install yarn globally for all projects. If you do not use –global, you need to install yarn manually for each project.
npm install --global yarn

Step 2: Check if yarn is installed successfully

To test if the yarn is installed successfully or not, run the following command on the bash terminal or command prompt.

yarn -version
yarn -version

Now it will show the installed version of the yarn application. If you are still getting yarn: command not found error then reverify if you have followed the above steps as mentioned.

Note: After setting the yarn installation path in the Path environment variable, make sure to use a new terminal to execute the yarn command. If you try to run the yarn command on the same terminal then you will again get the “yarn: command not found” error message.

That’s all about fixing the yarn command not found error. If you are still facing the issue then do mention it in the comment section or you can reach out to us using the contact form.

Leave a Comment

Your email address will not be published.

Scroll to Top