SNAFU with npm update -g

2019-08-10 03:21发布

问题:

I tried updating npm and all hell broke loose:

Environment check
✔ $HOME
✔ Yo
✔ Compass
✔ Ruby
✔ Git
✔ Node.js
✔ npm
dist: $ npm update -g
npm http GET https://registry.npmjs.org/envcheck
npm http GET https://registry.npmjs.org/bower
npm http GET https://registry.npmjs.org/generator-h5bp
npm http GET https://registry.npmjs.org/generator-mocha
npm http GET https://registry.npmjs.org/generator-zf5
npm http GET https://registry.npmjs.org/headstart
npm http GET https://registry.npmjs.org/cordova
npm http GET https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/generator-webapp
npm http GET https://registry.npmjs.org/yeoman-foundation
npm http GET https://registry.npmjs.org/yo
npm http GET https://registry.npmjs.org/phonegap
npm http GET https://registry.npmjs.org/npm
npm http 200 https://registry.npmjs.org/generator-h5bp
npm http GET https://registry.npmjs.org/yeoman-generator
npm http 200 https://registry.npmjs.org/envcheck
npm http 200 https://registry.npmjs.org/bower
npm http 200 https://registry.npmjs.org/generator-zf5
npm http 200 https://registry.npmjs.org/headstart
npm http 200 https://registry.npmjs.org/generator-mocha
npm http 200 https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http 200 https://registry.npmjs.org/cordova
npm http 200 https://registry.npmjs.org/generator-webapp
npm http 200 https://registry.npmjs.org/yeoman-foundation
npm http 200 https://registry.npmjs.org/nopt
npm http 200 https://registry.npmjs.org/yeoman-generator
npm http 200 https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http 200 https://registry.npmjs.org/yo
npm http 200 https://registry.npmjs.org/phonegap
npm http 200 https://registry.npmjs.org/glob
npm http 200 https://registry.npmjs.org/lodash
npm http 200 https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm/-/npm-2.1.14.tgz
npm http GET https://registry.npmjs.org/bower/-/bower-1.3.12.tgz
npm http GET https://registry.npmjs.org/envcheck/-/envcheck-1.1.0.tgz
npm http GET https://registry.npmjs.org/generator-zf5/-/generator-zf5-0.9.5.tgz
npm http GET https://registry.npmjs.org/generator-mocha/-/generator-mocha-0.1.6.tgz
npm http GET https://registry.npmjs.org/headstart/-/headstart-1.3.1.tgz
npm http GET https://registry.npmjs.org/generator-webapp/-/generator-webapp-0.5.1.tgz
npm http GET https://registry.npmjs.org/yo/-/yo-1.3.3.tgz
npm http GET https://registry.npmjs.org/cordova/-/cordova-4.1.3-nightly.2014.10.21.tgz
npm http GET https://registry.npmjs.org/phonegap/-/phonegap-4.1.2-0.22.10.tgz
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/node_modules/.bin/nopt'
npm ERR! error rolling back  nopt@1.0.10 { [Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/node_modules/.bin/nopt']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/grunt-cli/node_modules/.bin/nopt' }
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/node_modules/.bin/nopt'
npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/node_modules/.bin/nopt']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/grunt-cli/node_modules/.bin/nopt' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 14.0.0
npm ERR! command "node" "/usr/local/bin/npm" "update" "-g"
npm ERR! cwd /Volumes/3 TB LaCie/* Projects/14-03157 Frontgate Windows App/Working/app/bower_components/bootstrap/dist
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! path /usr/local/lib/node_modules/grunt-cli/node_modules/.bin/nopt
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/node_modules/.bin/nopt'
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/generator-h5bp/node_modules/yeoman-generator'
npm ERR! error rolling back  yeoman-generator@0.14.2 { [Error: EACCES, unlink '/usr/local/lib/node_modules/generator-h5bp/node_modules/yeoman-generator']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/generator-h5bp/node_modules/yeoman-generator' }
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob'
npm ERR! error rolling back  glob@3.2.11 { [Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/grunt-cli/node_modules/findup-sync/node_modules/glob' }
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/node_modules/resolve'
npm ERR! error rolling back  resolve@0.3.1 { [Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/node_modules/resolve']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/grunt-cli/node_modules/resolve' }
npm http 200 https://registry.npmjs.org/bower/-/bower-1.3.12.tgz
npm http 200 https://registry.npmjs.org/generator-mocha/-/generator-mocha-0.1.6.tgz
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/generator-mocha'
npm ERR! error rolling back  generator-mocha@0.1.6 { [Error: EACCES, unlink '/usr/local/lib/node_modules/generator-mocha']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/generator-mocha' }
npm http 200 https://registry.npmjs.org/headstart/-/headstart-1.3.1.tgz
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/headstart'
npm ERR! error rolling back  headstart@1.3.1 { [Error: EACCES, unlink '/usr/local/lib/node_modules/headstart']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/headstart' }
npm http 200 https://registry.npmjs.org/generator-webapp/-/generator-webapp-0.5.1.tgz
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/generator-webapp'
npm ERR! error rolling back  generator-webapp@0.5.1 { [Error: EACCES, unlink '/usr/local/lib/node_modules/generator-webapp']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/generator-webapp' }
npm http 200 https://registry.npmjs.org/cordova/-/cordova-4.1.3-nightly.2014.10.21.tgz
npm http 200 https://registry.npmjs.org/generator-zf5/-/generator-zf5-0.9.5.tgz
npm http 200 https://registry.npmjs.org/envcheck/-/envcheck-1.1.0.tgz
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/envcheck'
npm ERR! error rolling back  envcheck@1.1.0 { [Error: EACCES, unlink '/usr/local/lib/node_modules/envcheck']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/envcheck' }
npm http 200 https://registry.npmjs.org/phonegap/-/phonegap-4.1.2-0.22.10.tgz
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/bower'
npm ERR! error rolling back  bower@1.3.12 { [Error: EACCES, unlink '/usr/local/lib/node_modules/bower']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/bower' }
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/cordova'
npm ERR! error rolling back  cordova@4.1.3-nightly.2014.10.21 { [Error: EACCES, unlink '/usr/local/lib/node_modules/cordova']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/cordova' }
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/generator-zf5'
npm ERR! error rolling back  generator-zf5@0.9.5 { [Error: EACCES, unlink '/usr/local/lib/node_modules/generator-zf5']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/generator-zf5' }
npm http 200 https://registry.npmjs.org/yo/-/yo-1.3.3.tgz
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/yo'
npm ERR! error rolling back  yo@1.3.3 { [Error: EACCES, unlink '/usr/local/lib/node_modules/yo']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/yo' }
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/phonegap'
npm ERR! error rolling back  phonegap@4.1.2-0.22.10 { [Error: EACCES, unlink '/usr/local/lib/node_modules/phonegap']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/phonegap' }
npm http 200 https://registry.npmjs.org/npm/-/npm-2.1.14.tgz
sudonpm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
npm ERR! error rolling back  npm@2.1.14 { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/npm' }
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Volumes/3 TB LaCie/* Projects/14-03157 Frontgate Windows App/Working/app/bower_components/bootstrap/dist/npm-debug.log
npm ERR! not ok code 0
dist: $ sudo npm update -g

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
sudo: npm: command not found
dist: $ npm update
-bash: /usr/local/bin/npm: No such file or directory
dist: $ cd /
/: $ npm update -g
-bash: /usr/local/bin/npm: No such file or directory
/: $ npm --version
-bash: /usr/local/bin/npm: No such file or directory
/: $ where npm
-bash: where: command not found
/: $ which npm
/: $ envcheck
-bash: /usr/local/bin/envcheck: No such file or directory
/: $ curl http://npmjs.org/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   193  100   193    0     0    797      0 --:--:-- --:--:-- --:--:--   800
sh: line 1: html: No such file or directory
sh: line 2: syntax error near unexpected token `<'
'h: line 2: `<head><title>301 Moved Permanently</title></head>
/: $ npm update -g
-bash: /usr/local/bin/npm: No such file or directory
/: $ envcheck
-bash: /usr/local/bin/envcheck: No such file or directory
/: $ curl https://npmjs.org/install.sh | sudo sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   193  100   193    0     0    163      0  0:00:01  0:00:01 --:--:--   164
sh: line 1: html: No such file or directory
sh: line 2: syntax error near unexpected token `<'
'h: line 2: `<head><title>301 Moved Permanently</title></head>
/: $ npm update
-bash: /usr/local/bin/npm: No such file or directory

Nothing is working. Not Yeoman, Bower, Grunt, etc. All from and update.

Did I do something wrong?

What should I have done differently?

What the heck do I do now?

FYI, I'm still learning Unix CLI so speak, slowly, please :-)

Thank you in advance.

回答1:

When an upgrade fails due to permissions issues (which is what happened here... 'EACCES' basically means access denied), it usually means Node/NPM was originally installed in a location you need sudo to access. This is considered bad practice, but it is easy for beginners because sudo makes everything "just work" automagically, no matter where you install it. And now during the upgrade, you did not use sudo, which may change files you do have access to, while others throw errors and remain unmodified.

So:

Did I do something wrong? Yes. Most likely, during installation of Node, you used sudo. By doing so, you caused most future commands to need sudo as well. But you did not use it during the first upgrade attempt.

What should I have done differently? It is likely that if you had used sudo for that first initial upgrade attempt, it would have worked. The second time, when you did include sudo, failed because the first attempt (without sudo) destroyed your ability to use the npm command at all. So it failed for a different reason.

What the heck do I do now? Re-install from scratch is the only reliable way out. And if you're up for it, try to make it work without using sudo at all. By doing so, you guarantee that future commands, with or without sudo, will have enough access permissions to have their intended effect.

To completely re-install and make your machine clean and shiny again, see here: How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

I highly recommend the approach using Homebrew. If you do attempt to use sudo out of habit, it will yell at you.