lernbr
lernbr

Reputation: 471

NPM Mac OS error: EACCES: permission denied, access '/usr/local/lib/node_modules'

I'm trying to install gatsby-cli globally:

npm install -g gatsby-cli

I keep getting an access error and am not sure how to fix it.

enter image description here

Upvotes: 3

Views: 16763

Answers (4)

pullidea-dev
pullidea-dev

Reputation: 1803

change your file permissions .. like this

first check who owns the directory

ls -la /usr/local/lib/node_modules

it is denying access because the node_module folder is owned by root

drwxr-xr-x 3 root wheel 102 Jun 24 23:24 node_modules

so this needs to be changed by changing root to your user but first run command below to check your current user How do I get the name of the active user via the command line in OS X?

id -un

OR

whoami

then change owner

sudo chown -R [owner]:[owner] /usr/local/lib/node_modules

OR

sudo chown -R ownerName: /usr/local/lib/node_modules

OR

sudo chown -R $USER /usr/local/lib/node_modules

Upvotes: 1

Aritra Chakraborty
Aritra Chakraborty

Reputation: 12542

Adding sudo is not the correct approach because when npm runs under sudo the files it will create will have ownership of root. Which you cannot access/readonly from your current non-su user.

Recommended way is to reinstall node and npm, Maybe when you installed node you installed as sudo. Or changing the Global folder for NPM.

You can read more about it here.

Another way would be to reclaim the node_modules folder. Just paste this below line in terminal this should work as-is.

sudo chown -R $(whoami) /usr/local/lib/node_modules

Warning: Pleas use exact path /usr/local/lib/node_modules. Don't use /usr/local/lib/ or something.

Upvotes: 15

harshit kohli
harshit kohli

Reputation: 302

try to execute in super user mode(root user) like this

sudo npm install -g gatsby-cli

Upvotes: 5

Claudio Busatto
Claudio Busatto

Reputation: 761

If you are not administrator in your machine, you need to install global packages using sudo.

sudo npm install -g gatsby-cli

Upvotes: 4

Related Questions