npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules

add following lines to ~/.bashrc after installing npm:

npm set prefix ~/.npm
PATH="$HOME/.npm/bin:$PATH"
PATH="./node_modules/.bin:$PATH"

Execute following line after changes:

source ~/.bashrc

and as mentioned by @contemplator avoid using sudo


To all the warnings telling not to use sudo above, I'd add the following solution that worked pretty well for me while installing n, node version manager

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

This was taken from here: https://poopcode.com/missing-write-access-to-usr-local-lib-node-modules/

PS: for my specific use-case I also needed to run this one afterwards

sudo chown -R $USER /usr/local/bin/