How to fix npm ERR! code EACCES npm ERR! symlink '../lib/node_modules/package' -> '/usr/local/bin/package' in npm
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- Option 1: Use a Node version manager (recommended)
- Option 2: Change npm's default directory
- Option 3: Fix ownership of npm directories
- Verify the fix
# Install nvmcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash# Reload shellsource ~/.bashrc# Install Node.js (installs to ~/.nvm, no sudo needed)nvm install node# Now global installs work without permission errorsnpm install -g my-packagenpm linknpm ERR! code EACCESnpm 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
- 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
- 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'"
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 linkAdvanced 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:
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/binFrequently 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
- 📚npm Official Documentation
- 📖Docs: npm link(Official Docs)
- 💬SO: npm permission issues(Stack Overflow)