Resolving NPM EACCES permissions errors when installing packages globally
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 ownerName
with your actual user. Now if you try to install a global package with npm, there shouldn’t be a EACCES permissions error.