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
I like to use ubuntu groups to achieve this instead of changing owner. Its quite simple.
First install nodejs and npm using apt-get
sudo apt-get update && sudo apt-get install nodejs npm
Figure out who is logged in i.e username, run following command to see it in terminal
whoami
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
Run following to allow access to logged in user
sudo chmod 777 -R /usr/local && sudo chgrp $(whoami) -R /usr/local
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