Ostrov Ostrov - 1 month ago 26
Node.js Question

Permission denied when installing Browsersync via NPM

I can't install Browsersync https://www.browsersync.io/#install to my Mac OS Sierra. I installed node.js and after running command

npm install -g browser-sync


I'm getting error. What I'm doing wrong?

pavels-iMac:~ Pavel$ npm install -g browser-sync

npm ERR! tar.unpack untar error /Users/Pavel/.npm/browser-sync/2.17.2/package.tgz
npm ERR! Darwin 16.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "browser-sync"
npm ERR! node v4.6.0
npm ERR! npm v2.15.9
npm ERR! path /usr/local/lib/node_modules/browser-sync
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/browser-sync'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/browser-sync']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/browser-sync',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/browser-sync',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53',
npm ERR! 'FSReqWrap.oncomplete (fs.js:82:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/Pavel/npm-debug.log

Answer

The problem is described right in your output log:

npm ERR!  { [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/browser-sync']

permission denied

This is happening because -g (globally installed NPM modules) install into /usr/local/lib/node or /usr/local/lib/node_modules, a protected system folder.

The solution is also in the log output:

Please try running this command again as root/Administrator.

Therefore, to work around this, elevate using sudo when you install global modules:

$ sudo npm -g install <module>

(protip: make sure you read the log error messages clearly before asking for help)

Comments