You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Suggestion] Alternative for per-user NPM configuration so that claude does not want user to install into /usr as superuser. #43
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.
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
Reacted by Eric McDonald, Igor Kotenkov, niplav, Xiang ZHU, Maxime Beauchamp, forevercj18, Jordan Frey and Bob
Reacted by Igor Kotenkov, Geser Dugarov, Peter Stein, Maxime Beauchamp and samrosenbaum
> 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
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
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.)
Reacted by luyangsuper, Dibya Sarker and Rjae Easton
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.)
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.
Activity
binitshah commentedon Feb 25, 2025
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:
oclivegriffin commentedon Feb 26, 2025
I was also not able to do this.
following the suggestion first:
then trying the second suggestion:
emcd commentedon Feb 26, 2025
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.)oclivegriffin commentedon Feb 26, 2025
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
Sonderwoods commentedon Jun 11, 2025
Tried installing without the sudo, getting same error. (havent tried with sudo)
emcd commentedon Jun 11, 2025
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.)Rjae commentedon Jul 31, 2025
@emcd your steps worked 100% perfectly and subsequently no issues running
claude. Appreciate you and hope I may return the favor some day.github-actions commentedon Aug 7, 2025
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.