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
Install nvm (Node Version Manager): curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
Close and reopen terminal, then install Node: nvm install node
Verify installation: node -v && npm -v
If you can't use nvm: mkdir ~/.npm-global && npm config set prefix '~/.npm-global'
Add to PATH: export PATH=~/.npm-global/bin:$PATH (add to ~/.zshrc or ~/.bashrc)
Delete node_modules and package-lock.json, then run npm install again
Found an issue with this solution?
