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.

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.
try to execute in super user mode(root user) like this
sudo npm install -g gatsby-cli
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With