Getting permission denied error when installing npm package manager

Issue with npm setup

I’m trying to install npm on my Mac system but running into permission problems. When I execute the installation command, everything seems to download fine but then fails at the end.

The main error I’m seeing is:

npm ERR! Could not create /usr/local/lib/node_modules/___npm.npm
npm ERR! error installing [email protected] Error: EACCESS, Permission denied '/usr/local/lib/node_modules'
npm ERR! Error: EACCESS, Permission denied '/usr/local/lib/node_modules'

It looks like the installer can’t write to the node_modules directory even though I’m using sudo. Has anyone encountered this before? What’s the best way to fix these permission issues during npm installation?

I’m on macOS and this is a fresh attempt to get npm working on my development machine.

have u checked if node is installed correctly? sometimes reinstalling node can help with npm issues. just uninstall it and then install again, that fixed it for me before. also, double check the permissions on the directory.