enoent

EACCES errors during npm install using sudo

When you install npm modules globally on mac or linux and get errors like

env: node: No such file or directory
/usr/local/lib

or…

errno ENOENT
spawn ENOENT

or…

code EACCES
npm ERR! errno -13

Make sure you don’t run npm install with sudo. You shouldn’t do that.

Instead change the owner of the npm directories to yourself and run it without sudo.

To do this, first verify that the path to the npm directories is /usr/local using this command:

npm config get prefix

If it is, set the permissions with this command:

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Read more about this at npm.