如何在mac上更新nodejs?


2

我正在尝试使用自制软件在mac上安装nodejs,但是当我运行命令时:

brew install node

我收到以下错误:

Beginning with 0.8.0, this recipe now comes with npm.
It appears you already have npm installed at /usr/local/lib/node_modules/npm.
To use the npm that comes with this recipe, first uninstall npm with
`npm uninstall npm -g`, then run this command again.

If you would like to keep your installation of npm instead of
using the one provided with homebrew, install the formula with
the `--without-npm` option.

但是当我跑步时:

sudo npm uninstall npm -g

我明白了:

sudo: npm: command not found

当我运行命令时npm,我得到:

-bash: /usr/local/bin/npm: No such file or directory

所以我不确定它是否真的安装过。

我的节点版本是0.8.22(我不知道它来自哪里)。我应该如何将其更新到最新版本?


如果你使用自制软件,只需使用它而不是其他任何东西。我会首先尝试使用brew卸载。yiu还通过home-brew安装节点吗?
马克

如果brew list显示节点和npm,只需删除两个并重新开始?
bmike

对自制软件中的这个线程没有足够的了解npm在安装时如何破坏,但它可能会帮助你解决一些记录的变通方法,如单行npm安装npm_config_prefix=/usr/local/lib/node_modules; curl -sSL https://npmjs.org/install.sh | bash
bmike

Answers:


1

/usr/local/bin/npm一个破碎的符号链接?这会使sudo npm打印出错,command not foundnpm打印出错误No such file or directory

您可以尝试为节点创建新的符号链接:

$ rm /usr/local/bin/npm; brew unlink node; brew link node
Unlinking /usr/local/Cellar/node/0.10.5... 4 links removed
Linking /usr/local/Cellar/node/0.10.5... 5 symlinks created
$ sudo /usr/local/bin/npm uninstall npm -g

或使用/usr/local/opt/node/bin/npm

$ ls -l `brew --prefix node`
lrwxr-xr-x  1 lauri  admin  21 Jun 14 18:27 /usr/local/opt/node -> ../Cellar/node/0.10.5
$ sudo /usr/local/opt/node/bin/npm uninstall npm -g
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.