npm install permission denied (macOS)

I tried everything in this thread with no luck on Big Sur, but then I tried this:

sudo npm install -g yarn

And it worked!


For Mac;

Run this on the Terminal >

sudo chown -R $USER /usr/local/lib/node_modules

Check permissions of your project root with ls -l /Users/Marc/Desktop/Dev/masterclass/. If the owner is not $USER, delete your node_modules directory, try changing the owner of that directory instead and run npm install again.

cd /Users/Marc/Desktop/Dev
rm -rf ./masterclass/node_mdoules/
chown -R $USER ./masterclass/
cd masterclass    
npm install