快速上手

Claude Code 安装

本文档覆盖 Claude Code CLI 在 Windows、WSL、macOS 上的安装方法。安装完成后,请参考 千问配置 或 cc-switch-使用指南 进行 API 配置。

前置条件

项目要求
操作系统Windows 10/11、WSL2(Ubuntu 22.04+)、macOS 13+
Node.js18+(推荐 20+,仅 npm 安装方式需要)
网络可访问安装源(国内可能需要镜像或代理)

方法一:npm + 国内镜像(推荐,WSL/Linux)

最稳定,无需代理,适合国内网络环境。

# 确认 Node.js 版本
node --version   # 需要 v18+

# 一键安装
npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com

验证:

claude --version
# 输出示例:2.1.118 (Claude Code)

[!TIP] 如果 command not found

npm config get prefix
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

方法二:官方安装脚本(需代理或境外网络)

# Linux / WSL / macOS
curl -fsSL https://claude.ai/install.sh | bash

# 安装指定稳定版
curl -fsSL https://claude.ai/install.sh | bash -s stable
# Windows PowerShell
irm https://claude.ai/install.ps1 | iex
:: Windows CMD
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

方法三:winget(Windows 原生)

winget install --id Anthropic.ClaudeCode --exact --disable-interactivity --accept-package-agreements --accept-source-agreements

卸载旧版:

winget uninstall --id Anthropic.ClaudeCode --exact --disable-interactivity --accept-source-agreements

方法四:Homebrew(macOS)

brew install --cask claude-code

更新:

brew upgrade --cask claude-code

方法五:手动下载二进制(离线 / 无 Node.js)

VERSION=2.1.118

# Linux x64
curl -fsSL https://downloads.claude.ai/claude-code-releases/${VERSION}/claude-linux-x64 -o /tmp/claude

# Linux ARM64
# curl -fsSL https://downloads.claude.ai/claude-code-releases/${VERSION}/claude-linux-arm64 -o /tmp/claude

# macOS Apple Silicon
# curl -fsSL https://downloads.claude.ai/claude-code-releases/${VERSION}/claude-darwin-arm64 -o /tmp/claude

# 赋予权限并安装
chmod +x /tmp/claude
mv /tmp/claude ~/.local/bin/claude

方法六:Docker 安装

临时使用

docker run -it --rm \
  -v "$(pwd):/workspace" \
  -w /workspace \
  node:20-alpine \
  sh -c "npm install -g @anthropic-ai/claude-code --registry=https://registry.npmmirror.com && claude"

构建专用镜像

FROM node:20-alpine
RUN npm install -g @anthropic-ai/claude-code \
    --registry=https://registry.npmmirror.com
WORKDIR /workspace
CMD ["claude"]
docker build -t claude-code:latest .
docker run -it --rm -v "$(pwd):/workspace" claude-code:latest

安装后验证

claude --version      # 查看版本
claude --help         # 查看帮助
claude doctor         # 诊断配置

常见问题

安装后 command not found: claude

npm config get prefix
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

npm 权限报错(EACCES)

mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

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

npm 安装报网络错误

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

SSL 证书错误

sudo apt-get update && sudo apt-get install -y ca-certificates

卸载

# npm 方式
npm uninstall -g @anthropic-ai/claude-code

# 二进制方式
rm ~/.local/bin/claude

# Windows winget
winget uninstall --id Anthropic.ClaudeCode

# 清理配置(可选)
rm -rf ~/.claude

后续步骤

安装完成后,需要配置 API 才能使用:

  • 使用千问 API:参考 千问配置
  • 使用 CC Switch 管理多供应商:参考 cc-switch-使用指南

On this page