Mac – getting shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied in different places

macnode.js

This isn't an error I can reproduce on all macs, was able to run this no problem on a second laptop yesterday, and is an error I get from multiple locations attempting to do multiple tasks that are all failing

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied

I first noticed this when trying to install phantomjs via npm:

$ sudo npm install -g phantomjs
/usr/local/bin/phantomjs -> /usr/local/lib/node_modules/phantomjs/bin/phantomjs

> phantomjs@1.9.10 install /usr/local/lib/node_modules/phantomjs
> node install.js

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied

node.js:815
    var cwd = process.cwd();
                  ^
Error: EACCES, permission denied
    at Function.startup.resolveArgv0 (node.js:815:23)
    at startup (node.js:58:13)
    at node.js:906:3

npm ERR! Darwin 13.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "phantomjs"
npm ERR! node v0.10.32
npm ERR! npm  v2.0.0
npm ERR! code ELIFECYCLE
npm ERR! phantomjs@1.9.10 install: `node install.js`
npm ERR! Exit status 8
npm ERR! 
npm ERR! Failed at the phantomjs@1.9.10 install script.
npm ERR! This is most likely a problem with the phantomjs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node install.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls phantomjs
npm ERR! There is likely additional logging output above.

A similar issue also occurs when installing selenium-standalone package from node.js:

$ sudo npm install -g selenium-standalone
/usr/local/bin/start-selenium -> /usr/local/lib/node_modules/selenium-standalone/bin/start-selenium

> selenium-standalone@2.43.1-2.9.0-1 install /usr/local/lib/node_modules/selenium-standalone
> node install.js

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied

node.js:815
    var cwd = process.cwd();
                  ^
Error: EACCES, permission denied
    at Function.startup.resolveArgv0 (node.js:815:23)
    at startup (node.js:58:13)
    at node.js:906:3

Which seems to indicate it's not related to any specific node.js package, however other packages install fine(such as grunt-cli)

Finally in searching for answers to this, I've also found a few things which had problems but weren't able to solve the problem in question:

  1. Fixed permissions on my hard drive via disk utility, issues were found and fixed
  2. rebooted into recovery and repaired my disk, which also had issues
  3. sudo /usr/libexec/locate.updatedb had the same issue. people recommended enabling root, and running it. This allowed that command to run correctly, and subsequent runs did not have the same error anymore. However trying this same process with npm did not lead help

I'm not sure what else could be causing the problem.

Best Answer

After further searching, I ended up finding a working answer here. I needed the --unsafe-perm flag with npm install, which allowed the packages that weren't working to be installed correctly