To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.
mkdir ~/.npm-globalnpm config set prefix '~/.npm-global'export PATH=~/.npm-global/bin:$PATHsource ~/.profileor
source ~/.bash_profilenpm install -g jshintInstead 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-globalhttps://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally