npm command - sudo or not?

前端 未结 5 794
梦如初夏
梦如初夏 2020-12-01 03:11

Currently I always run sudo npm install but as I understand it\'s not correct.

I want to have opportunity not to use it as root/Adm

5条回答
  •  一个人的身影
    2020-12-01 03:48

    It's possible (and advisable) to npm install -g node modules without sudo.

    Check the permission of your /usr/local/share/npm/bin folder. I had installed node and npm through brew (without sudo) and that particular folder ended up being owned by root.

    This fixed it for once and for all:

    $ sudo chown $(whoami) /usr/local/share/npm/bin
    

    (As for disallowing sudo with npm: you'd have to tweak npm for that. Your own node code could make use of https://npmjs.org/package/sudo-block, npm install sudo-block)

    EDIT: even though this works, I no longer use -g. Instead use prefix (see next answer), or better yet use NIX https://unix.stackexchange.com/a/381797 (even on OSX)

提交回复
热议问题