npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules

user10378098 picture user10378098 · Oct 25, 2018 · Viewed 41.5k times · Source

I am trying to install monaca with this command.

npm install -g monaca

But right after getting these errors:

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules 
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13, npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }

Any idea how to solve this problem? Thank you

Answer

Shivam ashtikar picture Shivam ashtikar · Jan 13, 2019

add following lines to ~/.bashrc after installing npm:

npm set prefix ~/.npm
PATH="$HOME/.npm/bin:$PATH"
PATH="./node_modules/.bin:$PATH"

Execute following line after changes:

source ~/.bashrc

and as mentioned by @contemplator avoid using sudo