Skip to content

Instantly share code, notes, and snippets.

@sursir
Created November 29, 2017 06:51
Show Gist options
  • Save sursir/a8d1a50c1098a265b33f10945c2ec542 to your computer and use it in GitHub Desktop.
Save sursir/a8d1a50c1098a265b33f10945c2ec542 to your computer and use it in GitHub Desktop.
npm

Fixing npm permissions

Change npm's default directory to another directory

There are times when you do not want to change ownership of the default directory that npm uses (i.e. /usr) as this could cause some problems, for example if you are sharing the system with other users. Instead, you can configure npm to use a different directory altogether. In our case, this will be a hidden directory in our home folder.

  1. Make a directory for global installations:
  mkdir ~/.npm-global
  1. Configure npm to use the new directory path:
  npm config set prefix '~/.npm-global'
  1. Open or create a ~/.profile file and add this line:
  export PATH=~/.npm-global/bin:$PATH
  1. Back on the command line, update your system variables:
  source ~/.profile

Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):

  NPM_CONFIG_PREFIX=~/.npm-global
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment