Skip to content

[Suggestion] Alternative for per-user NPM configuration so that claude does not want user to install into /usr as superuser. #43

Closed

Description

@emcd

I'm not a Node developer; asked Claude for best way to install the package as a non-root user.

Error:

npm error   errno: -13,
npm error   code: 'EACCES',
npm error   syscall: 'mkdir',
npm error   path: '/usr/lib/node_modules/@anthropic-ai/claude-code'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It is likely you do not have the permissions to access this file as the current user
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.

Was able to successfully install as a normal user following Claude's advice.

Could consider a security warning for other people who might also be unfamiliar with Node.js/NPM and care about running as a non-root user.

Activity

  1. binitshah commented on Feb 25, 2025

    @binitshah

    I'll second this. On Ubuntu 22.04 & npm v10.5.0, I get the following error because it tries to install to /usr/lib/node_modules.

    $ npm install -g @anthropic-ai/claude-code
    npm ERR! code EACCES
    npm ERR! syscall mkdir
    npm ERR! path /usr/lib/node_modules/@anthropic-ai
    npm ERR! errno -13
    npm ERR! Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/@anthropic-ai'
    ...
    

    I'd rather not use sudo / install this system-wide. Thanks @emcd for the solution:

    mkdir ~/.npm-global
    npm config set prefix '~/.npm-global'
    export PATH=~/.npm-global/bin:$PATH         # add this to your bashrc!
    npm install -g @anthropic-ai/claude-code
    
  2. oclivegriffin commented on Feb 26, 2025

    @oclivegriffin

    I was also not able to do this.

    following the suggestion first:

    > sudo chown -R $USER:$(id -gn) /usr/local && sudo chmod -R u+w /usr/local
    Password: <i enter my password>
    chown: /usr/local: Operation not permitted

    then trying the second suggestion:

    > npm -g config set prefix /Users/oliclive-griffin/.npm-global
    npm ERR! code EACCES
    npm ERR! syscall mkdir
    npm ERR! path /usr/local/etc
    npm ERR! errno -13
    npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/etc'
    npm ERR!     at async mkdir (node:internal/fs/promises:859:10)
    npm ERR!     at async Config.save (/usr/local/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:771:5)
    npm ERR!     at async Config.set (/usr/local/lib/node_modules/npm/lib/commands/config.js:176:5)
    npm ERR!     at async Config.exec (/usr/local/lib/node_modules/npm/lib/commands/config.js:118:11)
    npm ERR!     at async module.exports (/usr/local/lib/node_modules/npm/lib/cli-entry.js:61:5)
    npm ERR!  Error: EACCES: permission denied, mkdir '/usr/local/etc'
    npm ERR!     at async mkdir (node:internal/fs/promises:859:10)
    npm ERR!     at async Config.save (/usr/local/lib/node_modules/npm/node_modules/@npmcli/config/lib/index.js:771:5)
    npm ERR!     at async Config.set (/usr/local/lib/node_modules/npm/lib/commands/config.js:176:5)
    npm ERR!     at async Config.exec (/usr/local/lib/node_modules/npm/lib/commands/config.js:118:11)
    npm ERR!     at async module.exports (/usr/local/lib/node_modules/npm/lib/cli-entry.js:61:5) {
    npm ERR!   errno: -13,
    npm ERR!   code: 'EACCES',
    npm ERR!   syscall: 'mkdir',
    npm ERR!   path: '/usr/local/etc'
    npm ERR! }
    npm ERR!
    npm ERR! The operation was rejected by your operating system.
    npm ERR! It is likely you do not have the permissions to access this file as the current user
    npm ERR!
    npm ERR! If you believe this might be a permissions issue, please double-check the
    npm ERR! permissions of the file and its containing directories, or try running
    npm ERR! the command again as root/Administrator.
    
    npm ERR! A complete log of this run can be found in: /Users/oliclive-griffin/.npm/_logs/2025-02-26T00_53_59_710Z-debug-0.log
  3. emcd commented on Feb 26, 2025

    @emcd
    ContributorAuthor

    sudo chown -R $USER:$(id -gn) /usr/local && sudo chmod -R u+w /usr/local

    chown: /usr/local: Operation not permitted
    then trying the second suggestion:

    This ticket is about helping people avoid what you tried above, @oli-clive-griffin . (Though recursively changing the ownership and permissions on /usr/local on a single-user system is less problematic than changing the recursively changing the ownership and permissions of /usr.)

    Did you already install with sudo npm install -g @anthropic-ai/claude-code? If so, then you probably want to uninstall it first: sudo npm uninstall -g @anthropic-ai/claude-code

    Then follow the steps which Binit helpfully copied from the Claude conversation:

    • Create a NPM packages directory for your user: mkdir ~/.npm-global
    • Configure NPM to look at the new directory for global packages: npm config set prefix '~/.npm-global'
    • Assuming that you are using Bash or Zsh (probably Zsh, since you seem to be on macOS), then ensure that any executables that you install with NPM can be found: export PATH=~/.npm-global/bin:$PATH
    • Attempt installation again: npm install -g @anthropic-ai/claude-code

    npm -g config set prefix /Users/oliclive-griffin/.npm-global

    This step should not be using the -g flag, as far as I know. Can you try without the -g on this step?

    If you still have problems, then it could have something to do with how you installed npm on your macOS system. (Providing some details on how you installed npm could aid in troubleshooting.)

  4. oclivegriffin commented on Feb 26, 2025

    @oclivegriffin

    I hate to not be helpful but I've now got this working and am under a lot of time pressure so likely won't be able to try this too soon. sorry

  5. added
    bug
    on Feb 28, 2025
  6. Sonderwoods commented on Jun 11, 2025

    @Sonderwoods

    Tried installing without the sudo, getting same error. (havent tried with sudo)

    npm ERR! code EACCES
    npm ERR! syscall symlink
    npm ERR! path ../lib/node_modules/@anthropic-ai/claude-code/cli.js
    npm ERR! dest /usr/local/bin/claude
    npm ERR! errno -13
    npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/@anthropic-ai/claude-code/cli.js' -> '/usr/local/bin/claude'
    npm ERR!  { [Error: EACCES: permission denied, symlink '../lib/node_modules/@anthropic-ai/claude-code/cli.js' -> '/usr/local/bin/claude']
    npm ERR!   cause:
    npm ERR!    { Error: EACCES: permission denied, symlink '../lib/node_modules/@anthropic-ai/claude-code/cli.js' -> '/usr/local/bin/claude'
    npm ERR!      errno: -13,
    npm ERR!      code: 'EACCES',
    npm ERR!      syscall: 'symlink',
    npm ERR!      path: '../lib/node_modules/@anthropic-ai/claude-code/cli.js',
    npm ERR!      dest: '/usr/local/bin/claude' },
    npm ERR!   stack:
    npm ERR!    'Error: EACCES: permission denied, symlink \'../lib/node_modules/@anthropic-ai/claude-code/cli.js\' -> \'/usr/local/bin/claude\'',
    npm ERR!   errno: -13,
    npm ERR!   code: 'EACCES',
    npm ERR!   syscall: 'symlink',
    npm ERR!   path: '../lib/node_modules/@anthropic-ai/claude-code/cli.js',
    npm ERR!   dest: '/usr/local/bin/claude' }
    npm ERR!
    npm ERR! The operation was rejected by your operating system.
    npm ERR! It is likely you do not have the permissions to access this file as the current user
    npm ERR!
    npm ERR! If you believe this might be a permissions issue, please double-check the
    npm ERR! permissions of the file and its containing directories, or try running
    npm ERR! the command again as root/Administrator.
    
  7. emcd commented on Jun 11, 2025

    @emcd
    ContributorAuthor

    Tried installing without the sudo, getting same error. (havent tried with sudo)

    npm ERR! code EACCES
    npm ERR! syscall symlink
    npm ERR! path ../lib/node_modules/@anthropic-ai/claude-code/cli.js
    npm ERR! dest /usr/local/bin/claude
    npm ERR! errno -13
    npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/@anthropic-ai/claude-code/cli.js' -> '/usr/local/bin/claude'
    

    Does not look like you have a user-writable NPM prefix, given that the Claude installation path is showing as /usr/local in the output you have provided. I would recommend setting a user-writable NPM prefix, per the instructions linked in the original post or on the Anthropic website. (Or, if you have Asdf, Mise, Nvm, etc..., you can install using a Node.js/npm provided by one of them.)

  8. Rjae commented on Jul 31, 2025

    @Rjae

    @emcd your steps worked 100% perfectly and subsequently no issues running claude . Appreciate you and hope I may return the favor some day.

  9. github-actions commented on Aug 7, 2025

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  10. locked as resolved and limited conversation to collaborators on Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions