Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM Mac OS error: EACCES: permission denied, access '/usr/local/lib/node_modules'

I'm trying to install gatsby-cli globally:

npm install -g gatsby-cli

I keep getting an access error and am not sure how to fix it.

enter image description here

like image 609
lernbr Avatar asked Oct 16 '25 11:10

lernbr


2 Answers

Adding sudo is not the correct approach because when npm runs under sudo the files it will create will have ownership of root. Which you cannot access/readonly from your current non-su user.

Recommended way is to reinstall node and npm, Maybe when you installed node you installed as sudo. Or changing the Global folder for NPM.

You can read more about it here.

Another way would be to reclaim the node_modules folder. Just paste this below line in terminal this should work as-is.

sudo chown -R $(whoami) /usr/local/lib/node_modules

Warning: Pleas use exact path /usr/local/lib/node_modules. Don't use /usr/local/lib/ or something.

like image 88
Aritra Chakraborty Avatar answered Oct 18 '25 01:10

Aritra Chakraborty


try to execute in super user mode(root user) like this

sudo npm install -g gatsby-cli
like image 42
harshit kohli Avatar answered Oct 18 '25 00:10

harshit kohli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!