I've just rebuild my Mavericks (Mac OS X Version 9.4) machine from scratch. I am the administrator and only user of this machine.
- I installed Git via their
git-2.0.1-intel-universal-snow-leopard.pkg
(http://git-scm.com/downloads) in their default/usr/local/git/bin/git
location. - I installed Node via their
node-v0.10.30.pkg
(http://nodejs.org/download/) in their default/usr/local/bin/node
location. - The final step of Node's installer package included a note that they also installed NPM in their default
/usr/local/bin/npm
location. - My
$PATH
echoes/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
) results in what appears to be the same list of errors.
Several people online suggest forcing the installation via sudo
, but several others warn this could cause later issues. The manuals for these packages seem not to mention requirement of sudo
, and in some cases, they have advised contacting NPM when this issue arises.
Running npm cache clear
does not correct the issue.
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 has gone wrong and how to correct this? Thank you.
EACCES is an error of not having access on doing an operation.
Taken the line:
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
we can see thatnpm
was unable to create a directory in the given location.The reason is very likely that you are not running the command as super user. In fact, the error log is even suggesting that:
To run as administrator, you have to prefix those commands with
sudo
. That is:sudo npm install -g bower
. You will be required to type in a password for security reasons.By the way, I solved this issue by changing the owner of
/usr/local
to be myself, in order to allow NPM to modules in its default location without further requiringsudo
for each package's installation.I'd recommend that you install Node.js using a version manager such as nvm. This way, you kill two birds with one stone:
Basically it's as easy as running
from the command line.
to start fresh remove prior node.js and npm installs as well as these :
~/.npmrc ~/.npm ~/tmp ~/.npm-init.js
to install nodejs and npm as yourself NOT root do these commands (linux) :
download source from : http://nodejs.org/download/
which puts it into dir defined by above --prefix
NODE_PATH so node can find dir for modules otherwise npm install xxx will put newly installed module into dir in curr dir :
do above AND use syntax : npm install xxxxx -g always use the -g for global
nodejs install gives you npm as well :
(SOLUTION ANSWER)
Hi Guys,
I had the same problem on my MacBook Pro 2018. After trie installing any dependency globally (with "-g" or "--global") I did receive an issue "EACCES" error (it's about permissions)
You could simply add "sudo" before your commands what will force it.
For example:
or
Enjoy!
It's generally not advised to run
sudo
unless absolutely necessary.For issues like this, NPM can solve many issues, and allow multiple node versions to be used, and selected depending upon your use case.
I had a similar issue setting up a new machine, and installing NPM took care of the issue.