Yarn not installing in nvm version node version

me-me picture me-me · Sep 4, 2018 · Viewed 26.6k times · Source

I'm running into an issue with yarn when I change my nvm version of node. I noticed when I check my ~/.nvm folder I see two node versions.

  • v8.11.0
  • v8.11.3.

I installed yarn globally. using npm install -g yarn when I was using v8.11.0.

I can see yarn in my

.nvm/versions/node/v8.11.0

But when I switch to nvm v8.11.3 or set my nvm alias default to v8.11.3
Yarn is no longer available. I tried doing a global install again hoping it would add it to my v8.11.3 folder but it keeps trying to add it to v8.11.0

I've even deleted folder v8.11.0 but it just recreates it when I run npm install -g yarn

How can I get it to install so I can use yarn using any node version switch in nvm

Answer

TMT picture TMT · Nov 1, 2018

When you install a new node version using nvm and then used npm to install yarn, you need to reinstall the yarn for the new node version.

Try:

nvm install 8.11.3
nvm use 8.11.3
npm install -g yarn

This will install yarn in:

.nvm/versions/node/v8.11.3/

You can then switch between 8.11.0 and 8.11.3 and your yarn will still work.