You can see the list of groups you are assigned by using a very simple command, normally the first group is your username itself. Running this command to change to owner to your currently logged in user should fix it all up, and allow you to install global NPM packages without sudo.
Actually, I was also having the same problem. I was running Ubuntu. Mine problem arises because I'd lost my public key of the Ubuntu. Even updating my system was not happening. It was giving GPG error. In that case, you can regain your key by using this command:. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more.
How to fix npm throwing error without sudo Ask Question. Asked 8 years, 6 months ago. Active 17 days ago. Viewed k times. System Darwin Additional logging details can be found in: npm ERR! Improve this question. Karl Hill 8, 3 3 gold badges 44 44 silver badges 73 73 bronze badges.
Chad Chad Please consider the solution using NVM : stackoverflow. NPM comes within node it is installed at the same time. Have a look at the Wikipedia page: en. Finally a solution better than sudo chown : github. Under OSX and installing node with the 0official pkg intaller this solution did not work. I used this one instead: stackoverflow. It explains the issue and the fix: docs.
Show 2 more comments. Active Oldest Votes. Improve this answer. Zeeshan Hassan Memon 7, 3 3 gold badges 37 37 silver badges 52 52 bronze badges. Noah Noah I thought that whoami was a placeholder, but it works typed literally as-is, so it must be a variable I don't understand.
The backticks around whoami ensure that it gets executed correctly and then placed into the chown command — Noah. Add a comment. Uninstall Node root permission will probably be required. This might help you. Then install NVM following instructions on this page. Install Node via NVM: nvm install node Now npm link , npm install -g will no longer require you to be root. Yves M. Of all the solutions posted the NVM solution here provided the best results for me.
Highly recommend using NVM rather than toying with permissions. None of these solutions worked for me. I installed node from the snap store but I could not run commands like npm install -g. But after trying the NVM solution everything worked smoothly. Thank you very much for your answer. Kevin Nagurski 1, 9 9 silver badges 23 23 bronze badges. Xilo Xilo 4, 1 1 gold badge 10 10 silver badges 2 2 bronze badges. I don't know why this still gets upvotes. It is a very bad practice to change the ownership of system directories to a particular user!
Please see answer below for other solutions like creating a separate group for node users. Joel Purra Joel Purra Watch OUT!!! To got this changes permanent, you have to add the export-command to your.
Community Bot 1 1 1 silver badge. This is a bad idea. You probably do not want system directories to be owned by a particular user. Beside serious security concerns this is also not multiuser compatible.
Here is a more generic and safer approach that supports multi-user as well. Now you can easily install your modules as user npm install -g generator-angular Some modules grunt, bower, yo etc.
Edit 3 years later I'd recommend to use Node Version Manager. Christopher Will Christopher Will 2, 3 3 gold badges 25 25 silver badges 39 39 bronze badges. If node is installed by sources, although multiuser would be a problem, all modules would work perfectly without the use of sudo. I mean, its official, right?
And if we don't trust the Node folks with installing Node, then, well, what are we doing here anyway? Install Node. What happens when a new version of node is released? What if you need version 4. Did you know version 9 is out now too? Check out this post for more on how to tackle multiple versions of node. So basically, whenever you try to install or search something via NPM, you get a long list of unhelpful errors and the command you're trying to run fails.
When you try it with "sudo" however, you get the desired output. This will happen even if you are logged in as an administrator. This problem normally occurs when there is some issue with the permissions and privileges pertaining to your NPM installation. Did you install NPM using root privileges? That can be one of the reasons to cause you to need root privileges every time you run a command.
Or this could also be caused by permission issues within your home directory in which case you will have to take back the ownership, which is one of the solutions I've listed below.
The Node Version Manager , or NVM, is a tool that allows developers to install as many versions of Node you need and without requiring root privileges too. I recommend using it and performing a reinstall after uninstalling the current NPM installation.
If this is the route you want to take, then follow these steps:.
0コメント