Aug 25, 2018

[HDGEM] How to change npm's default directory to another directory

Fixing npm permissions

You may receive an EACCES error when you try to install a package globally. This indicates that you do not have permission to write to the directories that npm uses to store global packages and commands.

You can configure npm to use a different directory altogether. For example, use a hidden directory in home folder.
  1. Make a directory for global installations:
     mkdir ~/.npm-global  
  2. Configure npm to use the new directory path:
     npm config set prefix '~/.npm-global'  
  3. Open or create a ~/.profile file and add this line:
     export PATH=~/.npm-global/bin:$PATH  
  4. 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 also use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):

Posted By Blogger to HDGEM at 11/01/2016 06:39:00 AM