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 notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm