简体   繁体   中英

Install Yarn after NPM

I need some help and clarification regarding Yarn installation process.

MacOS ver. 10.14.2

  1. I've installed Homebrew via official site ( ver. 2.0.1 ).
  2. I've installed NPM by downloading package from official site ( ver. 10.15.1 LTS ).
  3. Now when I tried to install yarn via brew install yarn

I have the following error:

The post-install step did not complete successfully
You can try again using `brew postinstall node`

As I undertand, NPM installs node locally, when, for instance, I try to use create-react-app . When I use Homebrew to install yarn , it tries to install node globally. And we have conflict here.

I've found suggestion to use:

sudo chown -R `whoami`:admin /usr/local/ 

I am not entirely sure what this command does.

So, the questions are:

  1. Why changing the owner of the folder should be a solution? How will it affect multi user system?
  2. What is the correct way to install yarn?
  3. Can be there any conflicts if node is installed globally and locally (app folder.)

PS Please correct me, if I have wrong understanding here.

As Trott points out, npm does not install Node. npm is a package manager that comes bundled with Node. If you install Node, you automatically install npm.

Why changing the owner of the folder should be a solution? How will it affect multi user system?

It's not. Changing the permissions of this folder is sometimes suggested as a workaround for when you have npm installed in a location owned by root. This can cause EACCES errors when you try to install packages globally.

What is the correct way to install yarn?

While you can install Yarn through the Homebrew package manager, I would recommend doing: npm install -g yarn .

Can be there any conflicts if node is installed globally and locally (app folder).

You can't install Node globally and locally. You can install multiple versions of Node on the same machine, however.


I'm not a big fan of having one global Node installation, as it makes it a pain to update (esp. if one application relies on an older version of Node) and, depending on how you install Node, it can lead to permissions errors.

The better way is to use a version manager. This will allow you to install multiple Node versions on your machine, avoid permissions errors and swap between these Node versions at will.

I would recommend using nvm . It works nicely on MacOS. The TL;DR for installing nvm is:

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

But I would encourage you to look at the project on GitHub and read its README. There is also a good tutorial on how to use it here .

Once you have Node installed using nvm, run npm install -g yarn to install Yarn globally and you should be off to the races.

Finally, you might want to read this tutorial on using npm, as it could help to clear up some of the concepts.

HTH

I have faced a problem after install yarn by running npm install -g yarn command in my OS Windows 10 Pro. That was showing yarn' is not recognized as an internal or external command operable program or batch file .

Whatever, I have found the solution:

After npm,

go to CMD from your windows PC,

write : *npm install -g yarn*

then,

Go to Environmental Variables set up. Edit Path and add new and paste:

C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\yarn\\bin\\

Restart your terminal. And then check again in your cmd by running :

*yarn* or *yarn --version*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM