[Suggestion] Alternative for per-user NPM configuration so that `claude` does not want user to install into `/usr` as superuser.
Status Fixed / completed
Maintainer reply ✓ Yes — emcd
Activity 8 comments · opened Feb 24, 2025 · closed Feb 28, 2025
💡 Likely answer: A maintainer (emcd, contributor)
responded on this thread — see the highlighted reply below.
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.
8 Comments
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.I'd rather not use sudo / install this system-wide. Thanks @emcd for the solution:
I was also not able to do this.
following the suggestion first:
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/localon 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-codeThen follow the steps which Binit helpfully copied from the Claude conversation:
mkdir ~/.npm-globalnpm config set prefix '~/.npm-global'export PATH=~/.npm-global/bin:$PATHnpm install -g @anthropic-ai/claude-codeThis step should not be using the
-gflag, as far as I know. Can you try without the-gon this step?If you still have problems, then it could have something to do with how you installed
npmon your macOS system. (Providing some details on how you installednpmcould aid in troubleshooting.)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
Tried installing without the sudo, getting same error. (havent tried with sudo)
Does not look like you have a user-writable NPM prefix, given that the Claude installation path is showing as
/usr/localin 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/npmprovided by one of them.)@emcd your steps worked 100% perfectly and subsequently no issues running
claude. Appreciate you and hope I may return the favor some day.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.