Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yarn global command not working

People also ask

Why yarn command is not working?

To solve the error "yarn: command not found", install the yarn package globally by running npm install -g yarn and restart your terminal. If the command fails, run it with sudo and make sure the correct PATH is set in your system's environment variable.

How do I update my yarn globally?

In order to update your version of Yarn, you can run one of the following commands: npm install --global yarn - if you've installed Yarn via npm (recommended) curl --compressed -o- -L https://yarnpkg.com/install.sh | bash if you're on Unix. otherwise, check the docs of the installer you've used to install Yarn.


You should add export PATH="$PATH:$(yarn global bin)" to your ~/.bash_profile or whatever you use. It would solve the issue.

Depending on how you installed it, Yarn's global folder varies for some reason. You can follow this issue here.


Update Dec 2018

Just updating the path didn't work for me. I had to also set the yarn prefix.

  • Ubuntu 18.04.1 LTS (bionic)
  • yarn 1.12.3
  • npm v3.5.2
  • node v8.10.0
  • zsh 5.4.2

Steps

  1. Confirm your global bin path

    yarn global bin
    

I got: /home/username/.yarn/bin

  1. set yarn prefix:

    make sure your yarn prefix is the parent directory of your bin directory. You can confirm by running

    yarn config get prefix
    

    when I ran this, my prefix was empty, so I set it:

    yarn config set prefix ~/.yarn
    
  2. add the following to ~/.bash_profile or ~/.bashrc

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

    for zsh users, be sure to add this line to ~/.zshrc

  3. restart your shell or start a new one

    bash -l or zsh


In my case yarn global bin wasn't working.

Try a brew reinstall yarn if that's how you installed yarn

👍🏻


Ran into this issue but on a Windows system. All I had to do was add the yarn global bin to the PATH variable.

setx path "%path%;c:\users\YOURUSERNAME\appdata\local\yarn\bin"

Remember to change YOURUSERNAME to your account username.

You can check where your global bin is by running

yarn global bin

And please don't forget to restart the CMD window that you're working on. Happy coding!

! WARNING !

When executing the command that %path%; in front of your yarn directory is very important. If you don't type it you will definitely replace all your system environment variables.

Option 2

Safer option would be would be to just 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


To reinstall run below.

brew install -g yarn

// Note:(updating homebrew) for Mac users.

brew reinstall yarn

// (if yarn is still not found)


AndrewD gave a great answer, but for those on Windows it's a bit different, especially step 3.

Please do not use the command setx as @Thapedict said. It will remove all your previous paths you had and replace it with only the given directory. If you want to use setx, I think there might be a flag to make it append the existing path variables, but I don't know which one. Using only setx will not append to it.

I would just do System Properties > Advanced > Environment Variables > Edit Path > New > c:\users\YOURUSERNAME\appdata\local\yarn\bin

to make sure you don't remove your previous variables.


On Ubuntu, I fixed by installing the package like this:

sudo yarn global add <package> --prefix /usr/local