Facebooktwitterredditpinterestlinkedintumblr

Yarn is a package manager for Javascript that has seen an increase in popularity in recent years. However, it also has one of the most common errors out there: yarn command not found. This can be frustrating, but here are some ways to get around this issue.

What is Yarn?

Yarn is a package manager for Javascript that was created in 2016 as an alternative to npm. It has seen an increase in popularity in recent years due to its speed and reliability. Yarn stands for “Yet Another Resource Negotiator”.

How to Check if Yarn is Installed?

If you’re not sure whether or not Yarn is installed on your system, you can check by running the command below.

$ yarn – version
-bash: yarn: command not found

This will give you the version of Yarn that is installed on your system. If this command gives you the error “yarn: command not found“, it means that Yarn isn’t installed and you’ll need to install it before continuing.

Is Yarn in Your Environment Variable?

The most common reason for this error is that the Yarn executable file isn’t in your PATH environment variable. This means that when you try to run yarn, it can’t find the yarn command and displays an error message instead.

Here is how to add yarn to your environment variable on Windows:

C:\Program Files (x86)\Yarn\bin

Here is how to add yarn to your environment variable on macOS:

export PATH="/usr/local/bin:$PATH"

Here is how to add yarn to your environment variable on Debian Linux:

export PATH="/usr/bin:$PATH"

How to Install Yarn?

If you have npm (Node Package Manager) installed, you can install Yarn by running the command below.

sudo npm install -g yarn

How to Reinstall Your Node Installation?

The Node Package Manager (npm) may have gotten corrupted on your system. Follow the steps below to perform the uninstallation, depending on the operating system you are running.

Windows:

  • Go to the Control Panel and uninstall the Node.js program.
  • Go to the Node.js download page to download the latest Node.js version.
  • Run the Windows Installer and follow the installation wizard.
  • The installer will install a new version of yarn.

macOS:

  • Go to the Node.js download page to download the latest Node.js version.
  • Run the macOS Installer and follow the installation wizard.
  • The installer will reinstall yarn automatically.

Debian Linux:

  • From the Terminal, remove the Node.js package.
sudo apt remove nodejs
sudo apt purge nodejs
sudo apt autoremove

Download and install the latest version of npm by running this command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

After the reinstallation of npm, install yarn by following the steps above.

Conclusion

You’ve completed the reinstallation process. Now you can get back to coding without any performance issues arising from malfunctioned versions of npm and Node.js.

We hope this has been helpful, but if there are any questions or comments about what we covered in this blog post, please feel free to comment below.

Thanks for reading!

Leave a Comment