Resolving NPM EACCES permissions errors when installing packages globally

Emad Dehnavi
2 min readDec 25, 2022

--

NPM EACCES permissions error

Few days ago I had to do a whole “Delete settings and content” on my MacBook, so I was busy doing a fresh installation of my dev tools & during installing a package globally ( npm install --global yarn in my case ) I faced to this error:

Error: EACCES: permission denied

So it’s a permission error, obviously! The main reason behind the error is because the following folders which npm package manager need during installing packages globally, are owned by root user, and my current user don’t have any permission on them:

/usr/local/lib/node_modules/
/usr/local/bin/
/usr/local/share/

You can verify this by running ls -la /usr/local/lib/node_modules and other two folders. Once you confirm that those folders are owned by root, then one way to fix the error, is to add your current user, as the owner of them. If you don’t know what is your current user, you can find it by running id -un or whoami in your terminal. Then you need to run the following command for all those folders:

sudo chown -R ownerName: /usr/local/lib/node_modules
sudo chown -R ownerName: /usr/local/bin/
sudo chown -R ownerName: /usr/local/share/

Remember to replace the ownerNamewith your actual user. Now if you try to install a global package with npm, there shouldn’t be a EACCES permissions error.

--

--

Emad Dehnavi
Emad Dehnavi

Written by Emad Dehnavi

With 8 years as a software engineer, I write about AI and technology in a simple way. My goal is to make these topics easy and interesting for everyone.

No responses yet