npm throws error without sudo

前端 未结 30 2420
清酒与你
清酒与你 2020-11-21 07:43

I just installed node and npm through the package on nodejs.org and whenever I try to search or install something with npm it throws the following error, unless I sudo the c

30条回答
  •  不要未来只要你来
    2020-11-21 08:20

    I like to use ubuntu groups to achieve this instead of changing owner. Its quite simple.

    1. First install nodejs and npm using apt-get

      sudo apt-get update && sudo apt-get install nodejs npm

    2. Figure out who is logged in i.e username, run following command to see it in terminal

      whoami

    3. You can see the list of groups you are assigned by using a very simple command, normally the first group is your username itself

      groups

    4. Run following to allow access to logged in user

      sudo chmod 777 -R /usr/local && sudo chgrp $(whoami) -R /usr/local

    5. Update npm and nodejs

      npm install -g npm

    You are allset, your user can run npm commands without sudo

    You can also refer to this link https://askubuntu.com/a/1115373/687804

提交回复
热议问题