NPM will not install any package on Mac. New, clean build. `EACCES` and other errors

I just rebuilt the Mavericks machine (Mac OS X version 9.4) from scratch. I am the administrator and sole user of this machine.

  • I installed Git through their git-2.0.1-intel-universal-snow-leopard.pkg ( http://git-scm.com/downloads ) in my default location /usr/local/git/bin/git .
  • I installed Node through their node-v0.10.30.pkg ( http://nodejs.org/download/ ) in my default location /usr/local/bin/node .
  • In the last step of the Node installation package, a note was added that they also installed NPM at their default location /usr/local/bin/npm .
  • My $PATH echo /usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin (it contains /usr/local/bin ).

Running npm install -g bower results in:

 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.3.0 npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "bower" npm ERR! cwd /Users/Home npm ERR! node -v v0.10.30 npm ERR! npm -v 1.4.21 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/Home/npm-debug.log npm ERR! not ok code 0 

Running similar installations ( npm install -g yo , npm install -g grunt , npm install -g nvm , npm install -g npm ) leads to what seems to be the same list of errors.

Several people on the Internet offer to force installation through sudo , but some others warn that this may lead to later problems. The manuals for these packages do not seem to mention the sudo requirement, and in some cases they advise contacting NPM when this problem occurs.

Running npm cache clear does not fix the problem.

Running ls -la in the home directory ( ~ ) shows my Mac OS X username as the owner of my .npm directory: drwxr-xr-x 15 admin staff 510 Aug 11 23:53 .npm

Does anyone know what went wrong and how to fix it? Thanks.

+7
bash terminal npm macos
source share
4 answers

By the way, I solved this problem by changing the owner of /usr/local to myself to allow NPM for the modules in their default location, without requiring sudo for every package installation.

 sudo chown -R `whoami` /usr/local 
+11
source share

EACCES is a failure to access the operation.

Taken line: npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower' npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower' we see that npm could not create the directory in this place.

It is likely that you are not using this command as root. In fact, the error log even assumes that:

npm ERR! Try to run this command again as root / Administrator.

To run as administrator, you must prefix these commands with sudo . I.e:

sudo npm install -g bower . You will need to enter a password for security reasons.

+5
source share

to start a new one, remove the previous node.js and npm installations, as well as the following:

~ / .npmrc ~ / .npm ~ / TMP ~ / .npm-init.js

to install nodejs and npm, since you are not root, run these commands (linux):

 mkdir ${HOME}/bin 

Download Source: http://nodejs.org/download/

 cd v0.10.30/ ./configure --prefix=${HOME}/bin/nodejs make -j8 make install 

which puts it in the directory above --prefix

 export PATH=${HOME}/bin/nodejs/bin:$PATH 

NODE_PATH, so node can find the directory for the modules; otherwise, npm install xxx will add the newly installed module to the directory in the directory:

 export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules 

do the above And use the syntax: npm install xxxxx -g always use -g for global

nodejs install also gives you npm:

 ls -la ${HOME}/bin/nodejs/bin 
0
source share

I would recommend you install Node.js using a version manager such as nvm . Thus, you kill two birds with one stone:

  • First you can manage multiple versions of Node.js on the same computer (which you want to do sooner or later).
  • Secondly, you will bypass all access problems that arise when installing Node.js without it. At least my experience.

Basically it's as easy as starting

 $ curl https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash 

from the command line.

0
source share

All Articles