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
Changing the owner on "system-global" folders is a hack. On a fresh install, I would configure NPM to use an already writable location for "user-global" programs:
Then make sure you add that folder to your path:
See @ErikAndreas' answer to NPM modules won't install globally without sudo and longer step-by-step guide by @sindresorhus with also sets
$MANPATH
.ISSUE: You (the user) don't have the right set of permissions for the directory.
The instant way out is to run the npm install using sudo, but this may give you the same error, or improper installation.
AND changing directory ownership is not a good option, a temporary patch.
Solution/Suggestion: Change npm's Default Directory (from official docs)
Back-up your computer before moving forward.
(optional) In case you have a erroneous installation, first uninstall it:
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a
~/.profile
or~/.bash_profile
file and add this line:export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables, or restart the terminal:
source ~/.profile
(optional) Test: Download a package globally without using sudo.
npm install -g jshint
As if we need more answers here, but anyway..
Sindre Sorus has a guide Install npm packages globally without sudo on OS X and Linux outlining how to cleanly install without messing with permissions:
Checkout the source of this guide for the latest updates.
Another great fix here to configure NPM properly, run the following commands :
Permissions you used when installing Node will be required when doing things like writing in your npm directory (
npm link
,npm install -g
, etc.).You probably ran node installation with root permissions, that's why the global package installation is asking you to be root.
Solution 1: NVM
On a development machine, you should not install and run node with root permissions, otherwise things like
npm link
,npm install -g
will need the same permissions.NVM (Node Version Manager) allows you to install Node without root permissions and also allows you to install many versions of Node to play easily with them.. Perfect for development.
nvm install node
Now
npm link
,npm install -g
will no longer require you to be root.Edit: See also https://docs.npmjs.com/getting-started/fixing-npm-permissions
Solution 2: Install packages globally for a given user
If you are on OSX or Linux, you can create a user dedicated directory for your global package and setup
npm
andnode
to know how to find globally installed packages.Check out this great article for step by step instructions on installing npm modules globally without sudo.
See also: npm's documentation on Fixing npm permissions.
In case
sudo chown -R $(whoami) ~/.npm
didn't work for you, or you need a non terminal command solution.The issue is that your user account does not have write permission to node_modules folder, so you can do the following
Open finder and press
cmd
+shift
+g
this will open go to folder with urlWrite the following path
/usr/local/lib/node_modules
and press goRight click on
node_modules
folder and chooseGet Info
Scroll down to
sharing & permissions
sectionUnlock to be able to make changes.
Press
+
and add your user accountMake sure that you choose
Read & Write
in privilege drop downNow you should be able to install packages without
sudo
and permission issues should be solved