在mac high sierra上安装npm

时间:2017-11-25 15:13:32

标签: node.js macos npm homebrew

我想在mac high sierra上安装node.js和npm https://gist.github.com/rcugut/c7abd2a425bb65da3c61d8341cd4b02d
我成功通过自制软件安装node.js,但无法安装NPM
我该怎么办?

Hoyeongui-MacBook-Air:~ hoyeongkim$ node -v
v8.9.1
Hoyeongui-MacBook-Air:~ hoyeongkim$ curl -L https://www.npmjs.com/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6255  100  6255    0     0   2628      0  0:00:02  0:00:02 --:--:--  2629
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
install npm@latest
fetching: https://registry.npmjs.org/npm/-/npm-5.5.1.tgz
module.js:538
    throw err;
    ^

Error: Cannot find module '/private/var/folders/jn/6wwl3xfd25x94ky333nhcxb80000gn/T/npm.58735/package/bin/read-package-json.js'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
added 1 package and removed 1 package in 0.846s
/usr/local/Cellar/node/8.9.1/bin/npm -> /usr/local/Cellar/node/8.9.1/lib/node_modules/npm/bin/npm-cli.js
/usr/local/Cellar/node/8.9.1/bin/npx -> /usr/local/Cellar/node/8.9.1/lib/node_modules/npm/bin/npx-cli.js
+ npm@5.5.1
updated 1 package in 1.687s
It worked

Hoyeongui-MacBook-Air:~ hoyeongkim$ npm
-bash: npm: command not found

2 个答案:

答案 0 :(得分:3)

我已经更详细地研究了这个。我使用自制程序安装了node并将我的PATH设置为/usr/local/bin,所以我选择了所有自制二进制文件。

因此,如果我检查哪个二进制文件和node版本,我看到我正在运行自制程序安装的那个:

which node
/usr/local/bin/node

并且版本自制安装:

node -v
v8.9.1

node自制安装也自动安装npm完全相同:

which npm
/usr/local/bin/npm

这也是最新的:

npm -v
5.5.1

所以,我不确定你为什么试图从源代码安装npm - 只需使用自制提供的那个。

如果我查看与自制安装node相关联的文件,我可以看到它包含npm

brew ls node --verbose | grep 'npm$' 

示例输出

/usr/local/Cellar/node/8.9.1/etc/bash_completion.d/npm
/usr/local/Cellar/node/8.9.1/libexec/bin/npm
/usr/local/Cellar/node/8.9.1/libexec/lib/node_modules/npm/bin/npm

答案 1 :(得分:0)

看起来通过brew安装node / npm变得越来越成问题。 如本页所述:http://www.alickwong.com/2017/07/06/npm-command-not-found-mac/最好直接安装Mac pkg