Why does npm need sudo for EVERYTHING?

后端 未结 3 1717
耶瑟儿~
耶瑟儿~ 2021-01-14 14:59

I don\'t know how I\'ve managed it but npm seems to need sudo for absolutely every command, even npm help does not work without sudo. If I use a co

相关标签:
3条回答
  • 2021-01-14 15:25

    Take ember project for example, I give all related project directory root:

    neil@neil-System-Product-Name:~/Projects/ember-quickstart$ sudo chown -R $(whoami) /home/neil/Projects/ember-quickstart/ neil@neil-System-Product-Name:~/Projects/ember-quickstart$ ember s Could not start watchman Visit https://ember-cli.com/user-guide/#watchman for more info. Livereload server on http://localhost:7020 Build successful (10679ms) – Serving on http://localhost:4200/ Slowest Nodes (totalTime => 5% ) | Total (avg)
    ----------------------------------------------+--------------------- Babel (18) | 7561ms (420 ms)
    Concat (8) | 1872ms (234 ms)
    Rollup (1) | 629ms

    0 讨论(0)
  • 2021-01-14 15:26

    I encountered the same error after a fresh install of 0.12.4 today; this solved the problem for me:

    sudo chown -R $(whoami):admin /usr/local/lib/node_modules
    

    In my particular case, I noticed that this folder was owned by '{some-large-integer-account}:wheel'...YMMV

    If that doesn't solve it, take a look at the ownership of the folders that are being blocked as mentioned in the EACCESS error trace. If you're not sure what the ownership should be, you can usually infer it from the sibling dirs' ownership.

    0 讨论(0)
  • 2021-01-14 15:36

    I had this as well on my machine. What I did to fix it (there are probably much less extreme ways) was to completely remove npm, and then did a fresh installation node.js (with which npm is included) from http://nodejs.org/ making sure I didn't install as root. That then allowed me to use npm without root (except for global installs).

    0 讨论(0)
提交回复
热议问题