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

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.


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
  1. Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
  1. 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
  1. 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.