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.
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. Add the directory to your system PATH
3.1. Open or create a ~/.profile file and add this line:
# add the npm-global to the system PATH
export PATH=$HOME/.npm-global/bin:$PATH
3.2. update ststem variables:
source ~/.profile
# add the npm-global to the system PATH
export PATH=$HOME/.npm-global/bin:$PATH
2. update system variables:
source ~/.bashrc
3.3. verify:
echo $PATH
4. Add node_module to $NODE_PATH
This step will let you use/include all your Node libraries in Node.
4.1. Open ~/.profile file and add this line:
# add node_module to NODE_PATH
export NODE_PATH=$HOME/.npm-global/lib/node_modules
4.2. update ststem variables:
source ~/.profile
# add node_module to NODE_PATH
export NODE_PATH=$HOME/.npm-global/lib/node_modules
2. update system variables:
source ~/.bashrc
4.3. verify:
echo $NODE_PATH
5. change the owner of the folder ./npm to the default user, instead of the root:
sudo chown your_user_name -R ~/.npm
sources