Fix npm Permission Denied Error | Generated by AI

Home 2025.08

The error you’re encountering, EACCES: permission denied, means your current user does not have write permissions to the /usr/local/lib/node_modules directory. This is a common issue when installing global npm packages on Linux or macOS.

How to Fix This Issue

You can use sudo to run the command as the root user, but this is not recommended for regular use, as it can lead to permission issues with npm packages later.

sudo npm install -g @anthropic-ai/claude-code

The best practice is to configure npm to use a directory in your home folder where you have write permissions.

  1. Create a global npm directory in your home folder:
    mkdir ~/.npm-global
    
  2. Configure npm to use this directory:
    npm config set prefix '~/.npm-global'
    
  3. Add the new directory to your PATH: Open your shell configuration file (e.g., ~/.bashrc, ~/.zshrc, or ~/.profile) and add this line:
    export PATH=~/.npm-global/bin:$PATH
    

    Then, reload your shell:

    source ~/.bashrc  # or ~/.zshrc, ~/.profile
    
  4. Retry the installation:
    npm install -g @anthropic-ai/claude-code
    

Option 3: Fix Permissions for /usr/local (Advanced)

If you want to keep using /usr/local, you can change its ownership to your user:

sudo chown -R $(whoami) /usr/local/lib/node_modules

Then retry the installation.


Recommendation: Use Option 2 to avoid permission issues in the future.


Back Donate