Skip to content

Instantly share code, notes, and snippets.

@SanthoshRaju91
Created May 30, 2018 12:02
Show Gist options
  • Save SanthoshRaju91/a00af69e007ee4164cf614edb1ed27e3 to your computer and use it in GitHub Desktop.
Save SanthoshRaju91/a00af69e007ee4164cf614edb1ed27e3 to your computer and use it in GitHub Desktop.
how to fix npm install - access permission issue

How to fix npm install 's - access permission issue.

This gist is targeted for users using any linux type OS.

Steps to fix it.

  1. Create a hidden directory named .npm-global in your home directory.

cd ~

  • to change your current directory to home directory.

mkdir .npm-global

  1. Change npm configuration prefix to point to the directory you have created.

cd ~/.npm-global

  • change to current directory to npm-global hidden folder.

pwd

  • prints the current working directory & copy the output.

npm config set prefix <paste-pwd-output>

  • paste the output of the above command in the placeholders <>, this will set the prefix to prefix directory you created.

So now whenever you do npm install -g of any package, it would reside in the directory you created.

  1. Last step is to set the npm executable scripts in your system path.

This is needed if you need to run a particular package commands like webpack or ng

Open your .bash_profile in vim editor

vim ~/.bash_profile

Now add the below line

export PATH=$PATH:<paste-pwd-output>/bin

  • Paste the pwd-output from the above command and end with /bin, as shown above in the export command.

Save the file and exit out of vim editor and finally run the below command to source your bash_profile

source ~/.bash_profile

Now your are set to run any npm commands without any permission issue.

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