Nodejs:Resolving EACCES permissions errors when installed from .pkg

I am a super fan of installing tools if a .pkg or .dmg is available instead of using tools like homebrew or nvm. Things worked well but recently I started getting errors when I tried to update some of my other node packages specifically the below error

Error: EACCES: permission denied, access '/usr/local/lib/node_modules'

I then found some solutions here https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally, where they mentioned reinstall of node using nvm or to change npm default directory. I then chose to go with nvm which seemed easier, but I encountered a problem, how to uninstall the existing nodejs which I installed via pkg. After a few search found this script from https://medium.com/@abuabdirohman/how-to-uninstall-node-js-that-installed-via-pkg-on-macos-ffab7cd852bb

sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

with this command I was able to uninstall nodejs and then I followed the steps here to install nvm and then

nvm install node

and thats it, I am back into business 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *