![无法安装 npm、无法删除 npm、无法访问任何命令、无法安装 Coffeescript](https://linux22.com/image/583954/%E6%97%A0%E6%B3%95%E5%AE%89%E8%A3%85%20npm%E3%80%81%E6%97%A0%E6%B3%95%E5%88%A0%E9%99%A4%20npm%E3%80%81%E6%97%A0%E6%B3%95%E8%AE%BF%E9%97%AE%E4%BB%BB%E4%BD%95%E5%91%BD%E4%BB%A4%E3%80%81%E6%97%A0%E6%B3%95%E5%AE%89%E8%A3%85%20Coffeescript.png)
我在 Mac OS X Lion 上,我刚刚使用 nodejs.org 的软件包安装程序安装了 node.js。Node.js 运行良好,并且 Node.js 附带 npm。我还安装了 homebrew。我只是想安装 coffeescript,但终端一直抛出错误。所以我决定检查我正在运行的 npm 版本。它一直抛出错误。每当我尝试使用任何 npm 命令时,它都会抛出相同的错误。我尝试单独安装 npm,但出现错误,当我尝试删除 npm 时也出现同样的错误。有人可以帮忙吗,这真是令人难以置信地沮丧。
当我调用 npm help 时出错
macbook-air:~ mcbeav$ sudo npm help
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: No such module
at Object.<anonymous> (/usr/lib/node_modules/npm/lib/utils/config-defs.js:5:21)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object.<anonymous> (/usr/lib/node_modules/npm/lib/utils/ini.js:43:18)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
macbook-air:~ mcbeav$
当我尝试通过终端安装 npm 时出现错误
All clean!
npm ERR! Error: EPERM, chmod '/usr/local/bin/npm'
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR!
npm ERR! System Darwin 11.3.0
npm ERR! command "/usr/local/bin/node" "/private/var/folders/g1/tn_gpxcj423d1dn_jx2g9gp40000gn/T/npm.1064/package/cli.js" "rm" "npm" "-gf"
npm ERR! cwd /private/var/folders/g1/tn_gpxcj423d1dn_jx2g9gp40000gn/T/npm.1064/package
npm ERR! node -v v0.6.17
npm ERR! npm -v 1.1.21
npm ERR! path /usr/local/bin/npm
npm ERR! code EPERM
npm ERR! message EPERM, chmod '/usr/local/bin/npm'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /private/var/folders/g1/tn_gpxcj423d1dn_jx2g9gp40000gn/T/npm.1064/package/npm-debug.log
npm not ok
npm ERR! error rolling back [email protected] Error: EPERM, chmod '/usr/local/bin/npm'
npm ERR! Error: EPERM, chmod '/usr/local/bin/npm'
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR!
npm ERR! System Darwin 11.3.0
npm ERR! command "/usr/local/bin/node" "/private/var/folders/g1/tn_gpxcj423d1dn_jx2g9gp40000gn/T/npm.1064/package/cli.js" "install" "-gf"
npm ERR! cwd /private/var/folders/g1/tn_gpxcj423d1dn_jx2g9gp40000gn/T/npm.1064/package
npm ERR! node -v v0.6.17
npm ERR! npm -v 1.1.21
npm ERR! path /usr/local/bin/npm
npm ERR! code EPERM
npm ERR! message EPERM, chmod '/usr/local/bin/npm'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /private/var/folders/g1/tn_gpxcj423d1dn_jx2g9gp40000gn/T/npm.1064/package/npm-debug.log
npm not ok
It failed
macbook-air:~ mcbeav$
当我尝试删除 npm 时出错
macbook-air:~ mcbeav$ sudo npm uninstall npm -g
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: No such module
at Object.<anonymous> (/usr/lib/node_modules/npm/lib/utils/config-defs.js:5:21)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object.<anonymous> (/usr/lib/node_modules/npm/lib/utils/ini.js:43:18)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
macbook-air:~ mcbeav$
答案1
原来是旧安装与新安装冲突。旧安装存储在
usr/bin
新的存储在
usr/local/bin
我必须使用命令来安装它
curl http://npmjs.org/install.sh | sudo clean=yes sh
并且它工作得很好,但对于遇到同样问题的人来说,这很令人沮丧