This gist is targeted for users using any linux type OS.
Steps to fix it.
- Create a hidden directory named .npm-global in your home directory.
cd ~
- to change your current directory to home directory.
mkdir .npm-global
- 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.
- 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.