简体   繁体   中英

Running npm install -g yo command gives -> ERR

I just tried to do a npm install but get this error.

npm install -g 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 12.5.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "yo"
npm ERR! cwd /Users/hemanth
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.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/hemanth/npm-debug.log
npm ERR! not ok code 0

I changed the permissions of /usr/local with chown, but I'm not sure if this affects my issue. How can i fix it?

Edit

Ah, I read your OS wrong, you're on a mac. I'll leave this here though as it might still work (assuming you installed node via Homebrew)


I've only recently been playing with npm on Linux and this is how I solved it...

First, set the global npm prefix to a local (to your user) install

mkdir ~/.node && npm config set prefix ~/.node

npm up to and including version 1.4.20 is buggy (it ignores prefix configuration) so first thing we're going to do is install the current npm local to your user.

npm install -g --prefix=~/.node npm

Now all that's left to do is update your environment variables. In ~/.bashrc or whatever your preference is...

if [ -d "$HOME/.node/bin" ]; then
    PATH="$HOME/.node/bin:$PATH"
fi

export NODE_PATH="$NODE_PATH:$HOME/.node/lib/node_modules"

Then source it and you're good to go

source ~/.bashrc

有关以下命令对您起作用的原因,请参见此链接

sudo npm install -g yo

try with

sudo mkdir -p /usr/local/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules
npm install -g yo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM