無法安裝 npm、無法刪除 npm、無法存取任何指令、無法安裝 Coffeescript

無法安裝 npm、無法刪除 npm、無法存取任何指令、無法安裝 Coffeescript

我使用的是 Mac OS X Lion,我剛剛使用了 nodejs.org 的軟體包安裝程式來安裝 node.js。 Node.js 運作良好, Node.js 附帶了 npm。我也安裝了自製程式。我只是想安裝 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 https://npmjs.org/install.sh | sudo clean=yes sh

對於其他遇到相同問題的人來說效果很好,非常令人沮喪

答案2

Error: EPERM, chmod '/usr/local/bin/npm'是一個權限錯誤。最有可能的是,權限/usr/local/bin/npm'不正確(可能不可執行?),或遺失。

您可以嘗試安裝先前版本的node.js。這也可能有助於審查這個問題。

相關內容