简体   繁体   中英

permissions installing yeoman with npm - eaccess?

I installed npm with homebrew and had to link it - i'm thinking this may be some part of the issue. This is all new to me so I am seeking any help. I am trying to install yeoman and some other things on a computer with

npm install -g yo

however it is spitting back the error -

   npm ERR! Darwin 14.0.0
 npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "yo"
 npm ERR! node v0.12.0
 npm ERR! npm  v2.5.1
 npm ERR! path /Users/Lynda/npm-global/lib/node_modules/yo/lib
 npm ERR! code EACCES
 npm ERR! errno -13 

npm ERR! Error: EACCES, unlink '/Users/Lynda/npm-global/lib/node_modules/yo/lib'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES, unlink '/Users/Lynda/npm-global/lib/node_modules/yo/lib']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Users/Lynda/npm-global/lib/node_modules/yo/lib' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! error rolling back Error: EACCES, unlink '/Users/Lynda/npm-global/lib/node_modules/yo/lib'
npm ERR! error rolling back     at Error (native)
npm ERR! error rolling back  { [Error: EACCES, unlink '/Users/Lynda/npm-global/lib/node_modules/yo/lib']
npm ERR! error rolling back   errno: -13,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/Users/Lynda/npm-global/lib/node_modules/yo/lib' }

I did a bunch of googling and can't find anything, could use some help! I'd like to avoid sudo'ing if I can. Thanks.

you can own the directory that npm is trying to install to, I too disliked having to sudo . In fact, NPM states that you shouldn't sudo as well .

try:

sudo chown -R `whoami` /Users/Lynda/npm-global/lib/node_modules

remember that this will bind it to your current user, whoami is a bash variable to get your user name.

My preferred way of installing node & npm on OSX:

Install node via homebrew without npm :

brew update
brew install node --without-npm
echo prefix=~/.node >> ~/.npmrc

Then install npm via the install script on npmjs.org :

If you're wild and crazy:

curl -L https://www.npmjs.org/install.sh | sh

Otherwise, download https://www.npmjs.org/install.sh , inspect to your satisfaction, chmod +x and execute it.

Then add $HOME/.node/bin to your path.

Note: If you've previuously installed node + npm via the graphical installer or homebrew, you'll want to remove the previous install before installing again. For instance, if you installed via the graphical installer:

rm -rf /usr/local/lib/node_modules
rm -rf /usr/local/include/node
rm -rf ~/.npm
mv ~/.npmrc ~/.npmrc-old

If you would like to avoid sudo'ing, I recommend you use a version manager for node such as nvm . This allows to install global packages without sudo and also to run different versions of node and/or io.js side by side.

If you see this:

npm ERR! Please try running this command again as root/Administrator.

Then sudo is probably exactly what you need to use. Try sudo npm install -g yo

As this line

npm ERR! Please try running this command again as root/Administrator

states, you need to have admin credentials to install the yeoman. So you can try with sudo 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