How to Install Claude Code on macOS, Linux and Windows (2026)
Installing Claude Code takes two steps: set up the runtime, run the official install command, then verify with claude --version. Most failed installs come down to three things: no write permission on npm's global directory, the command not being on your PATH, or network timeouts. This article goes through each OS and ends with a lookup table.
The Claude Code install commands here are based on the official documentation at the time of writing. Version requirements and command details may change, so treat the official documentation as authoritative.
What do you need before installing?
- A terminal: Terminal on macOS, any shell on Linux, PowerShell on Windows.
- If you use the npm route, Node.js and npm. The official documentation sets a minimum Node version; check its current wording.
- A network that can reach the official domains. This is the step most likely to fail from mainland China, and it gets its own section below.
Check your environment first:
node -v
npm -v
If both print a version number, your Node environment is fine. If the version is too old, upgrade Node before continuing.
How do you install: npm or the official script?
Global install with npm
This is the most common route, and the command is the same on all three systems:
npm install -g @anthropic-ai/claude-code
Do not prefix it with sudo. A directory installed with sudo is owned by root, which causes permission problems on every later update and run. If npm reports no write permission, see the error table below.
The official install script
The official documentation also offers a native install that does not depend on Node: a shell script for macOS/Linux and a PowerShell script for Windows. The exact commands and URLs change between versions, so copy the current ones from the official documentation rather than pasting from a third-party article. The advantage of this route is that you do not have to manage Node versions.
What should Windows users watch for?
On Windows, the official documentation describes native Windows and WSL support separately, and the prerequisites (for example Git for Windows) are also defined there. If you already use WSL, just follow the Linux steps inside a WSL terminal. For setting environment variables, see How to set an environment variable for your API key on Windows.
How do you verify the install?
claude --version
If it prints a version number, the command works. Then run claude inside a project directory; on first launch it asks you to choose a login method. The differences between login methods are covered in Claude Code: API key login vs. subscription login. For the first edit session, see How to use Claude Code: from install to your first code change.
How do you troubleshoot a failed install?
| Symptom | Common cause | What to do |
|---|---|---|
EACCES permission error | npm's global directory is owned by root | Don't use sudo. Move the npm global prefix to your home directory, or install Node through a version manager such as nvm |
claude: command not found | npm's global bin directory is not on PATH | Run npm prefix -g, add the bin directory under that prefix to PATH (on Windows, the prefix directory itself), then reopen the terminal |
| Node version errors | Node is older than required | Upgrade Node and reinstall |
ETIMEDOUT, ECONNRESET, stalled download | The network can't reach the npm registry or official domains reliably | Check the network first; for npm you can switch to a registry mirror you can reach |
| Installs but fails to connect on launch | Network or proxy settings | Work through the connection checklist layer by layer |
How do you confirm a PATH problem?
npm prefix -g
echo $PATH
On macOS/Linux, add <prefix>/bin to your shell config file (such as ~/.zshrc or ~/.bashrc) and open a new terminal. On Windows, add the matching directory to Path in the system environment variables. Always reopen the terminal afterward; existing windows won't pick up the new PATH.
How do you troubleshoot network timeouts?
A timeout during installation usually means the npm registry is unreachable. Run npm config get registry to see the current registry, then retry with one your network can reach.
A timeout after launch means either the proxy isn't taking effect or the official domain is unreachable. Two articles help you check: Claude Code connection timeouts and errors: a four-layer network checklist and Claude Code proxy settings not working. You can also look at the cdnping Anthropic API status page to see whether the official endpoint has been healthy recently and rule out an outage on their side, then use the online speed test to see how your network connects to the various AI APIs.
No Claude account: how do you use it after installing?
Claude Code is only a command-line client. After installing, it needs a working backend: a Claude subscription account, an Anthropic API key, or a compatible third-party endpoint. Beginners without an overseas credit card, or who don't want to tie the tool to an official account, can use the "change the endpoint URL" approach. The principle is explained in Custom API endpoints for Claude Code, Codex and OpenCode.
AGI Plan is one option that works this way. AGI Plan is a commercial partner of cdnping, and what follows sticks to facts:
- Monthly subscription, paid in RMB, no overseas credit card needed.
- You keep using Claude Code, Codex and similar tools and only change one endpoint URL; one quota can be switched between several capability groups.
- Using Claude Code does not require a Claude account. Setup is three steps: register with an emailed verification code, pick a plan and create a key, change one setting.
- The service states plainly that it is not an officially authorized channel, and some models are marked "overseas only"; see the AGI Plan models page for specifics.
For setup details, see the AGI Plan getting-started page. Before choosing, you may also want to read Can you use Claude Code without a Claude account? to understand the limits of this approach. If you plan to use any third-party relay, read the self-check methods in Are Claude API relays safe? first.
What should you do next?
- Run
claude --versionto confirm the install worked. - Decide how to log in: official subscription, API key, or a changed endpoint URL.
- Try it on a small project, then configure settings.json as needed.
If you're stuck at the install step, copy the exact error text from the table above and compare it against the troubleshooting section of the official documentation; that usually pins it down to one item.