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

I am trying to set up Node.js and NPM on a Ubuntu 14.04 machine but am having some trouble. On my first try I kept getting EACCES errors when trying to install packages(sometimes even with sudo), so I completely uninstalled node and npm. Now I’m trying to figure out how to install them in a way that won’t require me to run everything sudo and won’t give me EACCES errors.

I’d rather not use NVM, and other than that I’ve just found a bunch of scattered partial answers, some of which contradict each other, or just use slightly different syntax.

I’d really appreciate some help with this. I’ve just made the switch over to Linux from Windows and am trying to get set up so I can start working again.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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: (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?

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply