gyp WARN EACCES user "root" does not have permission to access the dev dir

node.jsPermissionsNpmRoot

node.js Problem Overview


Trying to

sudo npm install protractor -g

and the same notorious error/warning again (googled to no avail):

gyp WARN EACCES user "root" does not have permission to access the dev dir "/Users/dmitrizaitsev/.node-gyp/0.12.0"

What seems to happen is that node version 0.12.0 is downloaded and rebuilt, again and again during the same installation, despite of being the current node version on my machine:

node -v
v0.12.0

Questions:

  • The directory "/Users/dmitrizaitsev/.node-gyp/0.12.0" is actually missing! Why such a misleading message?

  • Why was this directory not created neither during the node v0.12.0 nor during the previous successful rebuild with node-gyp?

  • (Obviously) How can I prevent this from happening?

I run Mac OSX 10.8.5 if that is of any importance.

node.js Solutions


Solution 1 - node.js

UPDATE. There is a better way - changing npm's default global directory to user sub-directory to which you already have correct permissions, so no need to mess with system file's permissions or ownership in first place.

As recommended in https://docs.npmjs.com/getting-started/fixing-npm-permissions:

>1. Make a directory for global installations:

mkdir ~/.npm-global

>2. Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

> 3. Open or create a ~/.profile (or ~/.bash_profile etc) file and add this line (at the end of the file):

export PATH=~/.npm-global/bin:$PATH

> 4. On the command line, update your system variables:

source ~/.profile

or source ~/.bash_profile

See also Sindre Sorhus's guide on the topic: https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md


Have now figured what was wrong:

The directory had wrong permissions - it was not writable (which would have been a better error message than "accessible").

And because it was not writable, a temporary directory was used and deleted after every use, which is why the whole download had to run again and again.

The solution is to set user permissions with

sudo chown -R $USER <directory>

and never sudo npm again. It seems whenever you run sudo npm, all subdirectories created get wrong permissions, which will lead to problems later on.

See here for more details.

Solution 2 - node.js

Try with:

sudo npm install -g module --unsafe-perm

Solution 3 - node.js

That's because you do not have a folder in this directory "/Users/dmitrizaitsev/.node-gyp/0.12.0".

Just create a new folder named 0.12.0 which is the version number of your node

It will fix the problem.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDmitri ZaitsevView Question on Stackoverflow
Solution 1 - node.jsDmitri ZaitsevView Answer on Stackoverflow
Solution 2 - node.jsMiki NacucchiView Answer on Stackoverflow
Solution 3 - node.jsJack LeeView Answer on Stackoverflow