On npm install: Unhandled rejection Error: EACCES: permission denied

NpmPermissions

Npm Problem Overview


I have managed to corrupt my npm install, and whenever I try to install packages using npm install, I receive error messages along these lines:

> Unhandled rejection Error: EACCES: permission denied, open '/Users/marknorgate/.npm/_cacache/tmp/a449402d'

I have tried reinstalling node & npm, and I have also tried to relocate my npm cache elsewhere using these instructions but nothing works.

How can I get it working?

Npm Solutions


Solution 1 - Npm

Restore ownership of the user's npm related folders, to the current user, like this:

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config

Solution 2 - Npm

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

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

Solution 3 - Npm

This happens if the first time you run NPM it's with sudo, for example when trying to do an npm install -g.

The cache folders need to be owned by the current user, not root.

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config

This will give ownership to the above folders when running with normal user permissions (not as sudo).

It's also worth noting that you shouldn't be installing global packages using SUDO. If you do run into issues with permissions, it's worth changing your global directory. The docs recommend:

mkdir ~/.npm-global

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

Then updating your PATH in wherever you define that (~/.profile etc.)

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

You'll then need to make sure the PATH env variable is set (restarting terminal or using the source command)

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

Solution 4 - Npm

sudo npm cache clean --force --unsafe-perm

and then npm i goes normally

Solution 5 - Npm

Above answer didn't work for me. Just try to run your command with --unsafe-perm.

e.g

npm install -g node@latest --unsafe-perm

This seems to solve the problem.

Solution 6 - Npm

If none of suggestions in answers worked out, try the following command: npm cache clear --force. It worked for me.

I found it at https://github.com/vuejs/vue-cli/issues/1809.

Solution 7 - Npm

change ownership

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config 

worked for as i installed package using sudo

Solution 8 - Npm

just create folders _cache/tmp under .npm manually at location /Users/marknorgate/.npm/_cacache/tmp and run your command with administrator access

Solution 9 - Npm

sudo npm install --unsafe-perm=true --allow-root

This was the one that worked for me

Solution 10 - Npm

Simply do sudo npm cache clean --force --unsafe-perm and npm i will go normally.

Solution 11 - Npm

Solution 12 - Npm

Try using this: 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

Now use npm install it should work.

Solution 13 - Npm

you can try following command for expo :

sudo chown -R $USER:$GROUP ~/.expo

Solution 14 - Npm

as per npm community

sudo npm cache clean --force --unsafe-perm

and then npm install goes normally.

source: npm community-unhandled-rejection-error-eacces-permission-denied

Solution 15 - Npm

Simply run on terminal : sudo chown -R $(whoami) ~/.npm

This worked for me !!

Solution 16 - Npm

This one works for me:

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

I did not use the -g because I am the only user. I used a MacBook Air.

Solution 17 - Npm

sudo npm install -g @angular/cli

use this. it worked for me

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionserlingpaView Question on Stackoverflow
Solution 1 - NpmSrAxiView Answer on Stackoverflow
Solution 2 - NpmOsama RashidView Answer on Stackoverflow
Solution 3 - NpmRyu KentView Answer on Stackoverflow
Solution 4 - NpmMwangi GituathiView Answer on Stackoverflow
Solution 5 - NpmJunaid FarooqView Answer on Stackoverflow
Solution 6 - NpmLimView Answer on Stackoverflow
Solution 7 - NpmTechnologistView Answer on Stackoverflow
Solution 8 - NpmAnshuman JaiswalView Answer on Stackoverflow
Solution 9 - NpmBliteKnightView Answer on Stackoverflow
Solution 10 - NpmJames OkunladeView Answer on Stackoverflow
Solution 11 - NpmClaudia V.View Answer on Stackoverflow
Solution 12 - NpmAyushKatiyarView Answer on Stackoverflow
Solution 13 - Npmcesur bağcıView Answer on Stackoverflow
Solution 14 - NpmsachinsuthariyaView Answer on Stackoverflow
Solution 15 - NpmAkshita AgarwalView Answer on Stackoverflow
Solution 16 - NpmArly OrdonezView Answer on Stackoverflow
Solution 17 - Npmaishwarya talapuruView Answer on Stackoverflow