Blog

Install Claude Code with npm when the install script fails

The recommended way to install Claude Code is the install script, which downloads the program from downloads.claude.ai. Where that host is unreachable, for example in mainland China, the script fails. Claude Code is also published on npm, and installing it from npm does not touch downloads.claude.ai. Checked against Claude Code 2.1.312 on 30 October 2026.

The RoamAI teamPublished October 30, 2026

The install script error

The official install command is:

curl -fsSL https://claude.ai/install.sh | bash

On Windows PowerShell it is irm https://claude.ai/install.ps1 | iex. Both scripts first ask downloads.claude.ai for the latest version number. When that fails they stop with:

Failed to get a valid version from downloads.claude.ai (got unexpected content).

The next line says the download service is unreachable or not available in your region. If claude.ai itself is blocked, the script cannot be downloaded at all. In either case, install from npm as below.

Install Node.js 22 or newer

The npm package of Claude Code requires Node.js 22 or newer. Check your version:

node --version

If Node.js is missing or older than 22, install the LTS release from nodejs.org. In mainland China the npmmirror mirror has the same installers at https://npmmirror.com/mirrors/node/ and is usually faster.

Install from npm

Run this in a terminal on macOS or Linux, or in PowerShell or Command Prompt on Windows:

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

In mainland China, use the npmmirror registry:

npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com

Then check that it works:

claude --version

If you see a version number, Claude Code is installed. The npm package pulls in the build for your system as a separate npm package, so it comes from the same registry and never from downloads.claude.ai.

If macOS or Linux reports an EACCES permission error, the global npm folder needs administrator rights. Do not use sudo npm install. Install Node.js with nvm instead, or point npm's global folder at your home directory.

Updating

Run the install command again with @latest:

npm install -g @anthropic-ai/claude-code@latest --registry=https://registry.npmmirror.com

To stop typing --registry every time, make the mirror npm's default registry. This applies to every npm install on the computer:

npm config set registry https://registry.npmmirror.com

Claude Code also updates itself. To turn that off and choose when to upgrade, set the environment variable DISABLE_AUTOUPDATER=1.

Connect an API key

Anthropic does not serve mainland China, so there you connect Claude Code with an API key and a base URL rather than a claude.ai login. The settings are in Connect Claude Code to your API key. If it fails, look up the message in Claude Code API errors.

One key per person for Claude Code

RoamAI is a Claude API for teams: create an API key in the console and use it in Claude Code, Claude Desktop or an SDK. VIP adds lower usage prices, dedicated servers and a named contact.

Get started

← All posts