How do I install Node and NPM so I don't have to use sudo?

二次信任 提交于 2019-12-04 04:51:51
yvanscher

The problem that throws an EACCES is often a permissions issue on two folders:

There could be a permissions problem on your ~/.npm directory.

The full path to your '~/.npm' directory is '/Users/YOUR_USERNAME/.npm'; it stores various npm functionality. The easiest way to get to your home directory on a unix based system (I believe on linux as well) is to type 'cd'.

There could also a permissions problem on your /usr/local/lib/node_modules.

This is where npm tries to store your globally installed modules. It is the system level version of the 'node_modules' folder you find in basically any node.js project you make and install with dependencies.

I actually made a node package that will resolve this issue on a mac, although I'm not sure about Linux (because the paths to '.npm' and 'node_modules' may be different on linux), you could give it a shot? It basically reasserts you as the owner of those directories.

Here's the github page:

https://github.com/yvanscher/fixmynode (just a quick note this package might be out of date because of a weird build issue with the osenv dependency)

If you reinstall node you could try to change the permissions yourself with these commands (which should work in Linux):

sudo chown -R $(whoami) ~/.npm

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

NOTE: I'm not 100% sure that the paths '/usr/local/lib/node_modules' and '~/.npm' are correct for a Linux based Node/npm install. Can you post the full error message you get in the terminal?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!