简体   繁体   English

在 NPM 之后安装 Yarn

[英]Install Yarn after NPM

I need some help and clarification regarding Yarn installation process.我需要一些有关Yarn安装过程的帮助和说明。

MacOS ver. MacOS 版本10.14.2 10.14.2

  1. I've installed Homebrew via official site ( ver. 2.0.1 ).我已经通过官方网站(版本ver. 2.0.1 )安装了Homebrew
  2. I've installed NPM by downloading package from official site ( ver. 10.15.1 LTS ).我已经通过从官方网站( ver. 10.15.1 LTS )下载软件包来安装NPM
  3. Now when I tried to install yarn via brew install yarn现在,当我试图安装yarn通过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 .据我了解,NPM 在本地安装节点,例如,当我尝试使用create-react-app When I use Homebrew to install yarn , it tries to install node globally.当我使用 Homebrew 安装yarn ,它会尝试全局安装node 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?安装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. PS请纠正我,如果我在这里有错误的理解。

As Trott points out, npm does not install Node. 正如Trott指出的那样,npm不会安装Node。 npm is a package manager that comes bundled with Node. npm是Node附带的软件包管理器。 If you install Node, you automatically install npm. 如果安装Node,则会自动安装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. 有时建议您更改此文件夹的权限,作为在root拥有的位置中安装npm时的解决方法。 This can cause EACCES errors when you try to install packages globally. 当您尝试全局安装软件包时,这可能会导致EACCES错误。

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 . 虽然可以通过Homebrew软件包管理器安装Yarn,但我建议您这样做: 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. 您无法在全局和本地安装Node。 You can install multiple versions of Node on the same machine, however. 但是,您可以在同一台计算机上安装多个版本的Node。


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. 我不喜欢安装一个全局Node,因为它会使更新变得很麻烦(特别是如果一个应用程序依赖于旧版本的Node),并且取决于您如何安装Node,它会导致权限问题错误。

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. 这将允许您在计算机上安装多个Node版本,避免权限错误并随意在这些Node版本之间进行交换。

I would recommend using nvm . 我建议使用nvm It works nicely on MacOS. 它在MacOS上运行良好。 The TL;DR for installing nvm is: 用于安装nvm的TL; DR为:

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. 但我鼓励您在GitHub上查看该项目并阅读其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. 使用nvm安装Node后,运行npm install -g yarn全局安装Yarn,您应该开始比赛了。

Finally, you might want to read this tutorial on using npm, as it could help to clear up some of the concepts. 最后,您可能想阅读有关使用npm的教程 ,因为它可以帮助您清除一些概念。

HTH 高温超导

I have faced a problem after install yarn by running npm install -g yarn command in my OS Windows 10 Pro.通过在我的操作系统 Windows 10 Pro 中运行npm install -g yarn命令安装纱线后,我遇到了问题。 That was showing yarn' is not recognized as an internal or external command operable program or batch file .那是显示yarn' is not configured as an internal or external command operable program or batch file

Whatever, I have found the solution:无论如何,我找到了解决方案:

After npm,在 npm 之后,

go to CMD from your windows PC,从 Windows PC 转到 CMD,

write : *npm install -g yarn*写: *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\\ C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\yarn\\bin\\

Restart your terminal.重启你的终端。 And then check again in your cmd by running :然后通过运行再次检查您的 cmd:

*yarn* or *yarn --version*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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