When running 'npm install', you get EACCES errors indicating permission denied. This usually happens on macOS/Linux when npm was installed with sudo or when the global package directory has wrong permissions.

Never use sudo with npm. Instead, reconfigure npm to use a directory in your home folder for global packages, or use a version manager like nvm.

Step-by-Step Guide

1

Install nvm (Node Version Manager): curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

2

Close and reopen terminal, then install Node: nvm install node

3

Verify installation: node -v && npm -v

4

If you can't use nvm: mkdir ~/.npm-global && npm config set prefix '~/.npm-global'

5

Add to PATH: export PATH=~/.npm-global/bin:$PATH (add to ~/.zshrc or ~/.bashrc)

6

Delete node_modules and package-lock.json, then run npm install again

Found an issue with this solution?

Related Topics

npm gyp build failednode version mismatchpackage lock conflicts