Install @anthropic-ai/claude-code using Nix npm
I was installing claude-code
via Nix, but new releases take 2-3 days to appear in the nixpkgs-unstable
branch. I want to use npm
directly instead. By default, npm
installs global packages to the immutable Nix store, causing npm install -g
fails.
Based on this article, the solution is straightforward: configure npm
to use a writable prefix
directory. The required Nix configuration is (commit):
home.file = {
".npmrc".text = "prefix=~/.npm-global";
};
home.sessionPath = [
"$HOME/.npm-global/bin"
];
Now I can install claude-code
using npm
:
npm install -g @anthropic-ai/claude-code
The version today is:
$ claude --version
1.0.72 (Claude Code)
#nix
#npm