40

Now I have installed Node and Npm and I run this command in terminal (yes I am on a mac):

npm install -g bower

Which follows with this output from the terminal:

npm http GET https://registry.npmjs.org/bower
npm http 304 https://registry.npmjs.org/bower
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/bower']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/bower',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/bower',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "bower"
npm ERR! cwd /Users/Superfunnytogo
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! path /usr/local/lib/node_modules/bower
npm ERR! fstream_path /usr/local/lib/node_modules/bower
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/Superfunnytogo/npm-debug.log
npm ERR! not ok code 0
Device-365-352:~ Superfunnytogo$ npm install -g bower
npm http GET https://registry.npmjs.org/bower
npm http 304 https://registry.npmjs.org/bower
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/bower']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/bower',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/bower',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "bower"
npm ERR! cwd /Users/Superfunnytogo
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! path /usr/local/lib/node_modules/bower
npm ERR! fstream_path /usr/local/lib/node_modules/bower
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/Superfunnytogo/npm-debug.log
npm ERR! not ok code 0
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Hurricane Development
  • 2,449
  • 1
  • 19
  • 40
  • What is wrong about this question? – Hurricane Development Feb 07 '14 at 20:27
  • 4
    Nothing wrong with this question. Not everybody can be expected to know about `sudo`. And in this case, using `sudo` isn't necessarily the right answer anyways. Here's a +1 to remove your negative vote tally. – EasyCo Mar 21 '14 at 00:25

6 Answers6

90

You need root access or permissions to install globally! Try :

 sudo npm install -g bower
c0d3junk13
  • 1,162
  • 9
  • 6
19

Much better than using sudo is setting a user level prefix. For example in ~/.npmrc set:

prefix = ${HOME}/npm-global

to use this folder for packages installed with -g.

Then you also need to set your PATH environment variable to include ${HOME}/npm-global/bin.

Community
  • 1
  • 1
lrsjng
  • 2,615
  • 1
  • 19
  • 23
  • 1
    Thank you so much. This is exactly what I was looking for. Using sudo to fix this is like using a sledge hammer to drive in finishing nails! – Richard Rowell Jan 29 '17 at 07:14
4

you shouldn't sudo bower right? I mean sudo npm install -g bower will work BUT here's the message I got:

Additional error details: Since bower is a user command, there is no need to execute it with superuser permissions. If you're having permission errors when using bower without sudo, please spend a few minutes learning more about how your system should work and make any necessary repairs.

http://www.joyent.com/blog/installing-node-and-npm https://gist.github.com/isaacs/579814

You can however run a command with sudo using --allow-root option

1

If you've installed node/npm via Homebrew on OSX you may want to first run brew doctor and follow instructions before sudo-ing any system folders. In my case this brought up a nag about agreeing to an Xcode/iOS license:

Builds will fail! Agree to the license by opening Xcode.app or running: xcodebuild -license

After doing that and running a brew update I was able to install Bower globally as expected.

jsol
  • 11
  • 1
1

I know that it's an old thread but I run into the issue recently after reinstalling Yosemite and xCode tools. In case anyone else gets stuck, what helped me was using the commands:

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config

Following suggestion from the thread below: https://github.com/bower/bower/issues/2262

lrsjng
  • 2,615
  • 1
  • 19
  • 23
Kasia B M
  • 49
  • 1
  • 3
0

Using sudo with npm is discouraged.

Look here https://stackoverflow.com/a/18277225/1857521 for a better solution to an almost identical problem.

Community
  • 1
  • 1
sfotiadis
  • 959
  • 10
  • 24