'How to fix EACCES issues with npm install

Some of my node modules get installed but there are always these sort of issues on this particular linux mint machine

npm install 

npm ERR! Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json'
npm ERR!  { [Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/home/me/.npm/semver/3.0.1/package/package.json',
npm ERR!   parent: 'gulp' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm


Solution 1:[1]

This code fix it for me.

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

Solution 2:[2]

UPDATE. See this answer for a better way.


You have to set correct permissions (ownership) so npm can access your (sub)directories with your normal user permissions:

sudo chown -R $USER <directory>

where in your case <directory> is /home/me and -R is for recursive to also change ownership of all your subdirectories, which is exactly what you want. That should fix the EACCESS issue.

Sadly the advise to run the command as root/Administrator is wrong here.

You want to avoid running npm with sudo ever, as recommended by the npm creator Isaac Schlueter:

I strongly encourage you not to do package management with sudo! Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut. Sure, it’s fast and definitely going to cut through any obstacles, but you might actually want that obstacle to stay there.

See here for more details.

Solution 3:[3]

Try to use "sudo npx create-react-app app-name" it may still show error because some dependencies may be mising but a directory and the necessary files maybe created.

Solution 4:[4]

Set the correct permission to access the necessary directories.

In my case (Node & NPM Installation via Brew) on BigSur:

sudo chown -R $USER /Users/YOUR_USERNAME/node_modules

Solution 5:[5]

If you are still facing problem after running :

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

Run the npm install command with :

--unsafe-perm 

which will help you in installing the package with out any problem.

Solution 6:[6]

To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.

Back up your computer.

On the command line, in your home directory, create a directory for global installations:

mkdir ~/.npm-global

Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

In your preferred text editor, open or create a ~/.profile file and add this line:

export PATH=~/.npm-global/bin:$PATH

On the command line, update your system variables:

source ~/.profile

To test your new configuration, install a package globally without using sudo:

npm install -g jshint

(ref: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)

Solution 7:[7]

Add sudo before npm install . It will permit access to write .

sudo npm install [name of package].

Solution 8:[8]

To permanently fix this problem, please run:

sudo chown -R 1000:1000 "/home/$USER/.npm"

Solution 9:[9]

I understand one might be suspicious about changing the ownership of folders situated in the system files. But it's completely safe, they are meant to host processes that you can use without sudo. So I prefer this solution because it's good and will guarantee compatibility after.

sudo chown -R $USER /usr/local/bin
sudo chmod -R 0775 /usr/local/bin

sudo chown -R $USER /usr/local/lib/node_modules
sudo chmod -R 0775 /usr/local/lib/node_modules

If you installed a new version of node.js, you could still get some error. Try deleting the npm cache:

sudo npm cache clear

Solution 10:[10]

Running the code in sudo mode have fixed the problem for me

$ sudo npm install -g nativefier

And if you have related issues like package unmet dependencies check out this link

Solution 11:[11]

in windows run cmd as administrator and then try:

npm install -g <package-name>

in mac os or linux try:

sudo npm install -g <package-name>

Solution 12:[12]

sudo npm install -g create-react-app

just adding sudo before nmp install will give superuser privilages to run npm and that would not cause any erros while it want to alter a file or access it. well, i hope this might help you!

Solution 13:[13]

I had the Similar Problem when I typed:

npm install -g create-react-app

The Terminal replied:

npm ERR! code EACCES
....

So I add "sudo" like This:

sudo npm install -g create-react-app

And problem Solved!! :-) (So I am agree with "chethan chandan" about using "sudo")