gyp WARN EACCES user "root" does not have permission to access the dev dir
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 withnode-gyp
?(Obviously) How can I prevent this from happening?
I run Mac OSX 10.8.5 if that is of any importance.
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:
- 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
etc) file and add this line (at the end of the file):
export PATH=~/.npm-global/bin:$PATH
- 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.
Try with:
sudo npm install -g module --unsafe-perm
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.