“Error: EACCES: permission denied”
The npm documentation does provide a solution that works, which has a caveat.
- Make a directory for global installations:
- Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
- Open or create a ~/.profile file and add this line:
- Back on the command line, update your system variables:
As a side note, an easier way to execute step 3 is:
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile
When I initially executed these steps it worked. However, after logging out and in again the
pm2 command was no longer available. It turns out that on login the
.bash_profile file is loaded instead of the
.profile. Actually bash will try loading ~/.bash_profile, ~/.bash_login and ~/.profile, in that order. Once it finds one of them it will not try and load any of the others. After adding the statement to
.bash_profile it worked like a dream.
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bash_profile
Hope this helps someone.