Skip to content

Instantly share code, notes, and snippets.

@ntamvl
Created February 24, 2018 06:06
Show Gist options
  • Save ntamvl/41405b963c0e58959238c5871d2d30b7 to your computer and use it in GitHub Desktop.
Save ntamvl/41405b963c0e58959238c5871d2d30b7 to your computer and use it in GitHub Desktop.
NPM: How to Prevent Permissions Errors

NPM: How to Prevent Permissions Errors

This section does not apply to Microsoft Windows. This chapter will be updated to address Windows in the near future.

To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, it will be a hidden directory on your home folder.

Back-up your computer before you start.

Make a directory for global installations:

mkdir ~/.npm-global

Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

Open or create a ~/.profile file and add this line:

export PATH=~/.npm-global/bin:$PATH

Back on the command line, update your system variables:

source ~/.profile

Test: Download a package globally without using sudo.

npm install -g jshint

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

source: https://docs.npmjs.com/getting-started/fixing-npm-permissions

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