Npm ERR! code EACCES

I want to work on a project of mine. I had to factory restart my computer and needed to reinstall everything. I thought I did it and I went to run ionic serve to see my project and start working on it, the console says: zsh: command not found: ionic.

Not sure if this is necessary but the more info I can give I assume the better…

I am using a MacBook Air, running Monterey Version 12.7

node -v
npm -v
git -v
git version 2.37.1 (Apple Git-137.1)


When I try to run:
npm install -g @ionic/cli

it gives me this:

npm ERR! code EACCES

npm ERR! syscall mkdir

npm ERR! path /usr/local/lib/node_modules/@ionic

npm ERR! errno -13

npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@ionic'

npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@ionic'] {

npm ERR! errno: -13,

npm ERR! code: 'EACCES',

npm ERR! syscall: 'mkdir',

npm ERR! path: '/usr/local/lib/node_modules/@ionic'

npm ERR! }

npm ERR!

npm ERR! The operation was rejected by your operating system.

npm ERR! It is likely you do not have the permissions to access this file as the current user

npm ERR!

npm ERR! If you believe this might be a permissions issue, please double-check the

npm ERR! permissions of the file and its containing directories, or try running

npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in: /Users/zdisanto/.npm/_logs/2023-10-02T20_30_06_098Z-debug-0.log

What is going on and how do I fix this?

1 Like

that’s because, maybe, you used “sudo” command.

Anyway, to fix this type
sudo chmod -R 777 /usr/local/lib/node_modules/

after that try again

1 Like


I try my best not to use sudo at all. But now that you mention it I did try to look up this answer on a different forum and they told me to do this:

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

Before writing this above, I was still getting the error and decided to ask on here.

Will the code you provided:
sudo chmod -R 777 /usr/local/lib/node_modules/

undo what I typed/just work? Or will it add more errors?

Thank you for your time.

It will give those folders the rights to execute read and modify
Its safe

This helps me everytime:

Thank you for your help. That was where I went before this Forum and I tried that. Didn’t really work.

Does this work for you?
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Or you can install the CLI using sudo, but this is absolutely not recommended:
sudo npm install -g @ionic/cli