It's just my notes, or not?

[Solved] npm ERR! Error: EACCES: permission denied, access '/usr/local/lib'

Problem: when install an npm package in global.
you@computer:~/path $ npm install -g (package)
npm WARN checkPermissions Missing write access to /usr/local/lib
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib' }
...

Solution: configure npm to use a different directory for global installation.

1.Create a directory for global installation: $ mkdir ~/.npm-global 2.Configure npm to use the new directory path: npm config set prefix '~/.npm-global' 3.Add the directory to $PATH in the ~/.profile: echo 'export PATH="~/.npm-global/bin:$PATH"' >> ~/.profile 4.Update your system variables: source ~/.profile Test: Download a package globally without using sudo. npm install -g (something) If it still shows permission error (mac os), run: sudo chown -R $USER ~/.npm-global

No comments:

Post a Comment