macos 如何使用 Brew 安装最新版本的 Node

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5056115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:43:40  来源:igfitidea点击:

How to install latest version of Node using Brew

macoshomebrew

提问by PandaWood

The latest version of NodeJs right now is 0.4.1

NodeJs 现在的最新版本是 0.4.1

The command brew install noderight now, installs 0.2.6 - which is not ideal. I would like 0.4.1

brew install node现在的命令安装 0.2.6 - 这并不理想。我想要 0.4.1

I've looked at this list of commandsfor brew and tried brew install --HEAD node

我看过这个brew命令列表并尝试过brew install --HEAD node

But that installs node 0.5-pre.

但这会安装节点 0.5-pre。

Why isn't brew installing the right version and how can I force it to get the right one?

为什么 brew 不安装正确的版本,我如何强制它获得正确的版本?

At this stage, it looks like it would actually be easier just to download the src and install it manually. But I would like to know what's going on with Brew.

在这个阶段,看起来只需下载 src 并手动安装它实际上会更容易。但我想知道 Brew 发生了什么。

采纳答案by Lily Ballard

Have you run brew updatefirst? If you don't do that, Homebrew can't update its formulas, and if it doesn't update its formulas it doesn't know how to install the latest versions of software.

你先跑了brew update吗?如果你不这样做,Homebrew 就不能更新它的公式,如果它不更新它的公式,它就不知道如何安装最新版本的软件。

回答by Andrey Bodoev

Run commands below, in this order:

按以下顺序运行以下命令:

brew update
brew doctor
brew upgrade node

Now you have installed updated version of node, and it's probably not linked. If it's not, then just type: brew link nodeor brew link --overwrite node

现在您已经安装了更新版本的节点,它可能没有链接。如果不是,则只需键入:brew link nodebrew link --overwrite node

回答by Eric Walsh

After installation/upgrading node via brew I ran into this issue exactly: the node command worked but not the npm command.

通过 brew 安装/升级节点后,我正好遇到了这个问题:node 命令有效,但 npm 命令无效。

I used these commands to fix it.

我使用这些命令来修复它。

brew uninstall node
brew update
brew upgrade
brew cleanup
brew install node
sudo chown -R $(whoami) /usr/local
brew link --overwrite node
brew postinstall node

I pieced together this solution after trial and error using...

经过反复试验,我拼凑了这个解决方案,使用...

回答by Lance Pollard

Sometimes brew updatefails on me because one package doesn't download properly. So you can just upgrade a specific library like this:

有时brew update我会失败,因为一个包没有正确下载。所以你可以像这样升级一个特定的库:

brew upgrade node

https://gist.github.com/3005832

https://gist.github.com/3005832

回答by Alexandr

Also, try to deactivate the current node version after installing a new node version. It helps me.

此外,请尝试在安装新节点版本后停用当前节点版本。它帮助到我。

nvm deactivate

This is removed /Users/user_name/.nvm/*/bin from $PATH

这是从 $PATH 中删除的 /Users/user_name/.nvm/*/bin

And after that node was updated

在该节点更新之后

node --version
v10.9.0

回答by ojreadmore

I had to do brew link --overwrite nodeafter brew install nodeto update from 0.4 to 0.8.18

我必须brew link --overwrite nodebrew install node从 0.4 更新到 0.8.18之后做

回答by Reuben

Try to use "n" the Node extremely simplepackage manager.

尝试使用“n”这个 Node极其简单的包管理器。

> npm install -g n

Once you have "n" installed. You can pull the latest node by doing the following:

一旦你安装了“n”。您可以通过执行以下操作来拉取最新节点:

> n latest

I've used it successfully on Ubuntu 16.0x and MacOS 10.12 (Sierra)

我已经在 Ubuntu 16.0x 和 MacOS 10.12 (Sierra) 上成功使用了它

Reference: https://github.com/tj/n

参考:https: //github.com/tj/n

回答by Harikrishnan

If you have installed current node via Homebrew, just use these commands.

如果您已经通过 安装了当前节点Homebrew,只需使用这些命令。

brew update
brew upgrade node

Check node version by

检查节点版本

node -v

node -v

回答by user2096561

Just used this solution with Homebrew 0.9.5 and it seemed like a quick solution to upgrade to the latest stable version of node.

刚刚在 Homebrew 0.9.5 中使用了这个解决方案,它似乎是升级到最新稳定版本 node.js 的快速解决方案。

brew update

This will install the latest version

这将安装最新版本

brew install node

Unlink your current version of node use, node -v, to find this

取消链接您当前版本的节点使用,node -v,以找到它

brew unlink node012

This will change to the most up to date version of node.

这将更改为最新版本的节点。

brew link node

Note: This solution worked as a result of me getting this error:

注意:由于我收到此错误,此解决方案有效:

Error: No such keg: /usr/local/Cellar/node

错误:没有这样的桶:/usr/local/Cellar/node

回答by Mahendra Rao

  1. node -vwill show you the current version.
  2. npm -vwill show you the current version.
  3. brew link --overwrite --dry-run nodewill force the link and overwrite all conflicting files.
  4. brew install nodedo a fresh installation.
  5. brew update
  6. brew upgrade node
  7. brew link --overwrite node

    or

    brew link node

  1. node -v将显示当前版本。
  2. npm -v将显示当前版本。
  3. brew link --overwrite --dry-run node将强制链接并覆盖所有冲突的文件。
  4. brew install node进行全新安装。
  5. brew update
  6. brew upgrade node
  7. brew link --overwrite node

    或者

    brew link node

Node Upgrade Procedure are below

节点升级程序如下