Skip to content

Instantly share code, notes, and snippets.

@hsribei
Created May 4, 2017 23:12
Show Gist options
  • Save hsribei/e9489bb49ab361982f77ccac6289c3f1 to your computer and use it in GitHub Desktop.
Save hsribei/e9489bb49ab361982f77ccac6289c3f1 to your computer and use it in GitHub Desktop.
Remove need for sudo for npm install -g and yarn global add

This just follows Option 2 in this tutorial: https://docs.npmjs.com/getting-started/fixing-npm-permissions

The only difference is not using ~ because I read somewhere something chokes on it sometimes. So $HOME.

mkdir ~/.npm-global
npm config set prefix $HOME/.npm-global

in ~/.bashrc:

export PATH="$HOME/.npm-global/bin:$PATH"

This was done in a rage of frustration where I ended up wiping out all node/npm existence before finding something that works, so I have no idea if just following this will work on a machine that already has stuff installed via npm/yarn. If it does, please let me know.

@rulatir
Copy link

rulatir commented Jan 17, 2021

Does it really work with yarn too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment