8

Installing Yeoman on my OSX machine results in the following error:

paulh16$ npm install -g yo
npm http GET https://registry.npmjs.org/yo
npm http 304 https://registry.npmjs.org/yo
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/yo'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/yo']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/yo',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/yo',
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" "yo"
npm ERR! cwd /Users/paulh16/.rvm/lib
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! path /usr/local/lib/node_modules/yo
npm ERR! fstream_path /usr/local/lib/node_modules/yo
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/yo'
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/paulh16/.rvm/lib/npm-debug.log
npm ERR! not ok code 0

I believe the problem is that bash is looking for npm within the Ruby Version Manager, which is where I installed node and npm originally. However, I removed both from RVM and installed from the Node website. I also adjusted my .bash_profile:

PS1="\u$ "
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

if [ -f ~/.git-completion.bash ]; then
   source ~/.git-completion.bash
fi

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM$

I don't understand why the Yeoman installation is failing.

user1498724
  • 147
  • 1
  • 1
  • 5
  • The log snippet posted by you contains: `Please try running this command again as root` -- Does that give a clue? – devnull Dec 02 '13 at 14:10
  • That is correct. Instead of using sudo, refer to this article: http://aralbalkan.com/scribbles/npm-install-g-please-try-running-this-command-again-as-root-administrator/ – user1498724 Dec 02 '13 at 14:17
  • See the comments at http://stackoverflow.com/questions/20340387/errors-using-yeoman – Eddie Monge Jr Dec 03 '13 at 22:28

5 Answers5

32

This solved the issue for me. Setting the permission on the npm folder in your home directory was the fix for me.

sudo chown -R `whoami` ~/.npm
Szymon
  • 42,577
  • 16
  • 96
  • 114
Drew Hart
  • 421
  • 3
  • 3
23

The npm command fails because you need to be root to edit files under /usr/.

You should properly configure npm, see this relevant SO answer:

$ echo prefix = ~/.node >> ~/.npmrc
Community
  • 1
  • 1
Paul Mougel
  • 16,728
  • 6
  • 57
  • 64
  • 1
    Worked like charm! Thank you. And for newbies who doesn't understand what this code is doing - http://stackoverflow.com/questions/21948653/what-does-echo-prefix-node-npmrc-mean – Yehonatan Jun 09 '14 at 15:48
  • 1
    I just love this answer.. if it were a woman, I would marry it :) – whizcreed Apr 26 '15 at 09:56
14

try

sudo chown -R $USER /usr/local

and this kind of problem would be solved forever

it's not encouraged to npm with sudo

Maysam Torabi
  • 3,672
  • 2
  • 28
  • 31
0

For me on Ubuntu only the following worked for me...

Ubuntu

Tested on Ubuntu 14.04.2

This was a base install of Ubuntu 14.04.2 on VirtualBox using ubuntu-trusty-64.

I had just installed node and npm fresh and they were working well.

npm install -y -g yo
echo export PATH="$HOME/npm/bin:$PATH" >> ~/.bashrc
npm config set prefix ~/npm
echo "export NODE_PATH=$NODE_PATH:/home/$USER/npm/lib/node_modules" >> ~/.bashrc && source ~/.bashrc
npm install -y -g yo

yes I had to install yeoman, fix the path issues, then reinstall yeoman. based on some answers on this stack overflow post

Community
  • 1
  • 1
svnm
  • 22,878
  • 21
  • 90
  • 105
-4

This worked well for me:

sudo npm install -g yo
Mitchell Hudson
  • 1,013
  • 2
  • 10
  • 19
  • I might be wrong here but, if you install the yo as Admin then when you actually run yo command the terminal says it cannot be run as admin. But the @PaulMougel answer seems to work for me. It allowed me to install yo as regular user – Ajax3.14 Apr 27 '14 at 21:10
  • Should not be installed with sudo for the reason mentioned by @Ajax3.14 – grant Apr 30 '14 at 13:41