Unable to install npm global packages
Sep 23, 2021
Sometimes when you try to install global packages in npm , you might came across following error message as in screenshot
EACCES: permission denied, mkdir ‘/userdirectory/node_modules/<package you are trying to install>’
Now we can easily solve this issue by following below commands
- mkdir ~/.npm-global
- npm config set prefix ‘~/.npm-global’
- export PATH=~/.npm-global/bin:$PATH
- source ~/.profile
- npm install -g jshint
Lets understand what it does
- On the command line, in your home directory, create a directory for global installations
- Configure npm to use the new directory path
- In your preferred text editor, open or create a
~/.profile
file - On the command line, update your system variables
- Try to do it without sudo, it will work like charm