How to fix the “command not found yarn” error in Ubuntu, Windows or Mac (5 solutions)

There are a lot of queries by people asking “How to fix the command not found yarn” errors on forums. If you are also getting the same error, I will help you with all possible answers to get this issue solved. This Yarn command not found error may occur if you have not installed the package correctly or not set up the path variable. Let’s deep dive more into these fixes in this post.

Solutions provided in this post will also help you to fix the below-mentioned errors because the reasons are more or less the same.

  • yarn command not found windows
  • zsh command not found yarn
  • start command not found yarn
  • vue command not found yarn
  • bash: sequelize: command not found yarn
  • expo command not found after using yarn
  • bash: /usr/local/bin/yarn No such file for directory
command not found yarn error

Below mentioned are the possible reasons, why you get a “command not found yarn” error in your system.

  1. You have installed Yarn correctly
  2. You have not setup the Yarn path variable rightly
  3. PC reboot is missing after yarn package installation
  4. Re-installation of Yarn package is required

All these above-mentioned issues can be fixed if you know the right way to install Yarn on your system. Let me first show you the correct way on how to install yarn and set up the path variable in different operating systems.

Solution1 – Fix “command not found yarn” error by installing Yarn correctly

It is very important to know the right way to install yarn in your system. If you will miss any step, it may result in the yarn not found error.

Step1.1- Check if you have Yarn installed already

Check if you have installed already using the following commands.

  • If you use npm package manger
$ sudo npm -g list
npm -g list command to check yarn is installed or not
  • Or if you uses Ubuntu APT package manager
$ sudo apt list --installed | grep -i yarn
  • In case of macOS
$ brew list

If you have a yarn package already installed then skip to solution 2 otherwise follow solution1 to fix the command not found yarn error.

Step1.2 – Install Yarn using “NPM” package manager

Developers of yarn recommend installing the “Yarn” package using the npm package manager.

  • To install latest version 3 of yarn globally on your system run following command. This command applies to Ubuntu, Windows and macOS.
npm install -g yarn

To install a specific version use @package name

npm install -g yarn@version
  • Prefix sudo, in case of Ubuntu or Linux operating system
$ sudo npm install -g yarn
install yarn globally in Ubuntu using npm

If you get “npm command not found error”. It means npm package manager is not installed in your system. Follow this article on how to fix npm command not found error and come back.

  • Check yarn version
$ yarn --version

Step1.3 – Install Yarn using “APT” package manager

If you use Ubuntu and want to install yarn using the “apt” package manager, then follow these steps –

Step1.3.1 – Configure the yarn repository first

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

If you get a curl not found error, then install curl with apt install curl command.

Then run the following command after curl command

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Step1.3.2 – Update repository and install Yarn

sudo apt update && sudo apt install yarn

If you get errors due to “cmdtest“, remove it first

$ sudo apt remove cmdtest
  • If you are using nvm you can avoid the node installation by doing:
$ sudo apt update && sudo apt install --no-install-recommends yarn

Note: In some distros nodejs is used instead of nodeyarn might complain about node not being installed. As a workaround for this is just add an alias in your .bashrc file, like so: alias node=nodejs. This will point yarn to whatever version of node you decide to use.

Step1.4 – In case of macOS use script to install yarn

The easiest way to install yarn in macOS is via script

curl -o- -L https://yarnpkg.com/install.sh | bash

In case of any specific version, replace [version] with the yarn version name.

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]

In case of issues or alternate installation methods, you can check this link on the installation of Yarn in macOS.

Let’s move to the very important step of setting up path variable after yarn package installation

Solution2 – Make sure you setup the path variable correctly in your profile

Once you are done with yarn package installation, You need to make sure you have set up the yarn path correctly in your profile or environment variables.

Follow these steps depending upon your operating system to set up the Yarn path correctly.

Yarn bin directory path may differ with each installation and you must check the path first before setting it up. So that you won’t find a command not found error while running yarn.

Step2.1 – Check for Yarn global bin path

$ yarn global bin

Add the resulted path to your profile file. It may be .bashrc, .profile, .zshrc or .bash_profile in your case.

For example, I have added the following command to my .bashrc file to make yarn work.

$ export PATH="$PATH:$HOME/.config/yarn/global/node_modules/.bin"
  • Reload .bashrc profile file
$ source ~/.bashrc
  • In case of macOS

Edit .zshrc file and add the following path

export PATH="$PATH:`yarn global bin`"

Or you can also provide an absolute path like in the .zshrc file –

 $ export PATH="$PATH:$HOME/.config/yarn/global/node_modules/.bin" 

Then reload ~/.zshrc file

$ source ~/.zshrc

Note* In case you don’t have .bashrc, .profile or .zshrc file in your home directory. You can create one by “touch” command, vi or nano editor.

  • In case of Windows, edit environment variable by following method and replace path “c:\users\yourusername\appdata\local\yarn\bin” with your yarn global path.
Go to System Properties > Advanced > Environment Variables > select PATH the click Edit > then append and not replace with ;c:\users\YOURUSERNAME\appdata\local\yarn\bin.

Solution3 – Reboot the PC at least once after yarn installation to fix command not found yarn error

It has been seen that if you don’t restart your PC after Yarn installation and setup of a path variable. Sometimes you may get a “command not found yarn” issue. So always reboot your system to complete the installation of Yarn.

Solution4 – Re-install Yarn package, especially in case of macOS

If you have installed the Yarn package using Brew and still you are getting a command not found yarn error. You should try reinstalling it once. it has been seen for many users, it has resolved the problem.

  • To install yarn globally using homebrew, if you are not using npm package manager.
$ brew install -g yarn
  • To reinstall yarn, in case it’s corrupted or yarn global bin command is not working.
$ brew reinstall yarn

Solution5 – Setup the Yarn prefix

Sometimes, setting up the path variable doesn’t work, so may you need to set up the Yarn prefix. Follow these steps

Step5.1 – Find your global bin path of yarn

$ yarn global bin
Find installation path of yarn

Example, i have got /home/dev/.yarn/bin

Step5.2 – Set yarn prefix

$ yarn config get prefix
how to set yarn prefix

If you get no output after running above mentioned command, then run the following command to set prefix with path found with yarn global bin command.

$ yarn config set prefix /home/dev/.yarn
set yarn prefix as yarn global bin path

Step5.3 – Setup your .bash_profile, bashrc, .profile or .zshrc file

Add the following lines to your profile

export PATH="$PATH:`yarn global bin`"

Step5.4 – Restart your shell once with bash -l or zsh command

Restart your shell with the bash -l or zsh command. Alternatively close and open your terminal again.

How to check Yarn version

To check yarn version run –

$ yarn --version
How to check version of yarn

Frequently asked questions

Q1- What is the command to install yarn?

To install yarn using the npm package manager, which is the best way to install, run –

> npm install -g yarn

or in the case of Ubuntu or Linux, use sudo

$ sudo npm install -g yarn

Q2- How do I update the latest version of Yarn?

To install the latest version or to update yarn using npm. Run

> npm install –global yarn

in the case of macOS, if you have not used npm, then run

$ brew upgrade yarn

For more installation and upgrade options visit this link.

Q3- Which is better Yarn or NPM?

The yarn actually defeats NPM in terms of speed and performance. Yarn is secure and can install multiple packages at once compared to NPM, which installs packages one at a time.

Q4- Can Yarn work on Windows?

Yes, Yarn works on Windows pretty well. You can use npm, msi installer or chocolatey method to install yarn on Windows 10 as per your requirement or preference.

Q5- Where is yarn installed in Mac?

Run yarn global bin command to check the location of yarn installation. Yarn installation folder differs depending upon installation method and operating system. The default path of Yarn installation is generally “~/.config/yarn/global“.

End note

I hope after reading this article, you would have solved your “command not found yarn” error and at least one of the solutions has fixed your issue.

Please let me know, which method helps you to get this issue resolved. If you still facing this error, let me know the details, I will try to help you.

Keep Reading!!

Dev

I'm Dev, your friendly neighbourhood Tech Savy. I spend my days with gadgets, servers, and the occasional laugh-inducing software mishap. Think of me as your tech-savvy, glitch-prone buddy. If you've got questions, feedback, or just need someone to blame when your Wi-Fi goes haywire, I'm your guy!