isaacs/npm — Issue #1972: Running `npm update -g` kills npm install
Author: jswartwood
Created: 2011-12-30 19:14:10+00:00
State: open

I'm running node v0.6.6 and npm v1.1.0-beta-4 (the npm bundled w/ node) on osx.

I thought that npm update -g should be able to update npm to the latest version, but instead it fails because of permissions (I'm not surprised about this) and breaks the installed npm in the process (this is the issue).

My output:

$ npm update -g
npm http GET https://registry.npmjs.org/npm
npm http 304 https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm/1.0.106
npm http 304 https://registry.npmjs.org/npm/1.0.106
npm ERR! error installing npm@1.0.106
npm ERR! error rolling back npm@1.0.106 Error: EACCES, permission denied '/usr/local/lib/node_modules/npm/.gitmodules'
npm ERR! Error: EACCES, permission denied '/usr/local/lib/node_modules/npm/.gitmodules'
npm ERR! Report this *entire* log at:
npm ERR!
npm ERR! or email it to:
npm ERR!
npm ERR!
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/usr/local/bin/npm" "update" "-g"
npm ERR! cwd /Users/jswartwood
npm ERR! node -v v0.6.6
npm ERR! npm -v 1.1.0-beta-4
npm ERR! path /usr/local/lib/node_modules/npm/.gitmodules
npm ERR! code EACCES
npm ERR! message EACCES, permission denied '/usr/local/lib/node_modules/npm/.gitmodules'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/jswartwood/npm-debug.log
npm not ok
$ npm
-bash: /usr/local/bin/npm: No such file or directory

The problem is solved via running with `sudo` instead...

$ sudo npm update -g
Password:
npm http GET https://registry.npmjs.org/npm
npm http 304 https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm/1.0.106
npm http 304 https://registry.npmjs.org/npm/1.0.106
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npm_g -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npm-g -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm@1.0.106 /usr/local/lib/node_modules/npm

...but the permissions problem should simply throw an error and fail gracefully, and not require a node/npm reinstall.