This error occurs when npm lacks permission to create symlinks in global directories like /usr/local/bin. Usually happens when Node.js was installed with sudo or as root.
The EACCES (Access Denied) error during symlink creation means npm is trying to write to a directory your user doesn't own. This typically happens when: - Node.js was installed system-wide (with sudo or as root) - The global npm directories (`/usr/local/lib/node_modules` and `/usr/local/bin`) are owned by root - You're running npm without sudo (which is correct, but the directories need fixing) The solution is NOT to use sudo with npm—that creates more permission problems. Instead, configure npm to use directories you own.
Install Node.js via nvm, which manages permissions automatically:
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Reload shell
source ~/.bashrc
# Install Node.js (installs to ~/.nvm, no sudo needed)
nvm install node
# Now global installs work without permission errors
npm install -g my-package
npm linkConfigure npm to use a directory in your home folder:
# Create directory for global packages
mkdir -p ~/.npm-global
# Configure npm to use it
npm config set prefix ~/.npm-global
# Add to PATH (add to ~/.bashrc or ~/.zshrc)
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
# Now npm link works
npm linkTake ownership of the npm directories (quick fix):
# Fix ownership of npm directories
sudo chown -R $(whoami) /usr/local/{lib/node_modules,bin,share}
# Fix npm cache ownership
sudo chown -R $(whoami) ~/.npm
# Now npm link works
npm linkNote: This modifies system directories. Options 1 or 2 are cleaner long-term solutions.
Test that global operations work:
# Test global install
npm install -g cowsay
cowsay "It works!"
# Test npm link
cd /path/to/my-package
npm linkNever use sudo with npm: Running sudo npm install -g or sudo npm link creates root-owned files that cause more permission problems later. It's also a security risk since npm packages can run arbitrary scripts.
macOS with Homebrew: If you installed Node via Homebrew, fix permissions with:
sudo chown -R $(whoami) $(brew --prefix)/*Why nvm is best: nvm installs Node.js in your home directory, so all global packages are installed where you have full permissions. No sudo needed, no permission errors.
Corepack users: If using corepack for Yarn/pnpm:
corepack enable --install-directory ~/.local/binnpm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error