I just installed node and npm through the package on nodejs.org and whenever I try to search or install something with npm it throws the following error, unless I sudo the command. I have a feeling this is a permissions issue? I am already the admin.
npm ERR! Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json'
npm ERR! { [Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/chietala/.npm/-/all/.cache.json' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.2.0
npm ERR! command "node" "/usr/local/bin/npm" "search" "bower"
npm ERR! cwd /Users/chietala
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! path /Users/chietala/.npm/-/all/.cache.json
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/Users/chietala/.npm/-/all/.cache.json'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/chietala/npm-debug.log
npm ERR! not ok code 0
John Papa points to the history and reasoning behind this issue and gives a solid fix:
John Papa's steps are to:
Hope this helps the curious!
Watch OUT!!! Watch OUT!!! Watch OUT!!!
chown or chmod is NOT the solution, because of security-risk.
Instead do this, do:
First check, where npm point to, if you call:
If /usr is returned, you can do the following:
This create a npm-Direktory in your Home-Directory and point npm to it.
To got this changes permanent, you have to add the export-command to your .bashrc:
The official documentation on how to fix
npm install
permissions with anEACCES
error is located at https://docs.npmjs.com/getting-started/fixing-npm-permissions.I encountered this problem after a fresh install of node using the
.pkg
installer on OSX. There are some great answers here, but I didn't see a link to npmjs.com yet.Option 1: Change the permission to npm's default directory
Find the path to npm's directory:
For many systems, this will be /usr/local.
WARNING: If the displayed path is just /usr, switch to Option 2.
Change the owner of npm's directories to the name of the current user (your username!):
This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
Option 2: Change npm's default directory to another directory
There are times when you do not want to change ownership of the default directory that npm uses (i.e. /usr) as this could cause some problems, for example if you are sharing the system with other users.
Instead, you can configure npm to use a different directory altogether. In our case, this will be a hidden directory in our home folder.
Make a directory for global installations:
Configure npm to use the new directory path:
Open or create a ~/.profile file and add this line:
Back on the command line, update your system variables:
Here are the steps, in detail ...
Install Node.js from nodejs.org/en/download
Update to the latest version of npm:
$ npm install npm -g
Make a new folder for the npm global packages
$ mkdir ~/.npm-packages
Tell npm where to find/store them
$ npm config set prefix ~/.npm-packages
Verify the install
Hope it works for you, it worked for me!
When you run npm install -g somepackage, you may get an EACCES error asking you to run the command again as root/Administrator. It's a permissions issue.
It's easy to fix, open your terminal (Applications > Utilities > Terminal)
** I strongly recommend you to not use the package management with sudo (sudo npm -g install something), because you can get some issues later **
Reference: http://foohack.com/2010/08/intro-to-npm/
If changing permissions for directory
/usr/local/lib/npm_modules
not helps, u should add your user to group (in most cases this isstaff
group), that has rwx rights for/usr/bin
directory. Because npm tries to makesymlink
with/usr/bin/__package__
.P.S. Don't forget to relogin after changing user group