How to fix npm ERR! code EACCES npm ERR! symlink '../lib/node_modules/package' -> '/usr/local/bin/package' in npm

npmBEGINNERMEDIUMUpdated Dec 5, 2025· 177 views

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.

Quick fix

Fixes npm ERR! code EACCES npm ERR! symlink '../lib/node_modules/package' -> '/usr/local/bin/package'

# 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 link
  1. Option 1: Use a Node version manager (recommended)
  2. Option 2: Change npm's default directory
  3. Option 3: Fix ownership of npm directories
  4. Verify the fix
npm — error
# 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 link
npm ERR! code EACCES
npm ERR! symlink '../lib/node_modules/package' -> '/usr/local/bin/package'

What this error means

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.

Typical symptoms

  • npm link fails with 'EACCES' permission error
  • npm install -g fails with permission denied
  • Error mentions /usr/local/bin or /usr/local/lib
  • Works with sudo but that causes other issues

Common causes

  1. Node.js installed with sudo creating root-owned directories
  2. Global npm directories owned by root
  3. npm prefix points to system directory user can't write to
  4. Previous sudo npm operations created root-owned files

How to fix "npm ERR! code EACCES npm ERR! symlink '../lib/node_modules/package' -> '/usr/local/bin/package'"

1Option 1: Use a Node version manager (recommended)

Install Node.js via nvm, which manages permissions automatically:

bash
# 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 link
2Option 2: Change npm's default directory

Configure npm to use a directory in your home folder:

bash
# 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 link
3Option 3: Fix ownership of npm directories

Take ownership of the npm directories (quick fix):

bash
# 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 link

Note: This modifies system directories. Options 1 or 2 are cleaner long-term solutions.

4Verify the fix

Test that global operations work:

bash
# Test global install
npm install -g cowsay
cowsay "It works!"

# Test npm link
cd /path/to/my-package
npm link

Advanced notes

Never 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:

bash
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:

bash
corepack enable --install-directory ~/.local/bin

Frequently asked questions

What does "npm ERR! code EACCES npm ERR! symlink '../lib/node_modules/package' ->" mean?
The EACCES (Access Denied) error during symlink creation means npm is trying to write to a directory your user doesn't own. 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.
How do I fix "npm ERR! code EACCES npm ERR! symlink '../lib/node_modules/package' ->"?
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.
What causes "npm ERR! code EACCES npm ERR! symlink '../lib/node_modules/package' ->"?
Node.js installed with sudo creating root-owned directories Global npm directories owned by root npm prefix points to system directory user can't write to
Is the "npm ERR! code EACCES npm ERR! symlink '../lib/node_modules/package' ->" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading