
本 Install Claude Code 指南提供2026年最新的完整安装步骤,涵盖 macOS、Windows、Linux 三大平台,以及国内用户的特殊配置技巧。
目录
系统要求
在 Install Claude Code 之前,确认系统满足以下要求:
| 项目 | 要求 |
|---|---|
| 操作系统 | macOS 10.15+, Ubuntu 20.04+/Debian 10+, Windows 10+ (WSL/Git Bash) |
| 内存 | 最低 4GB,推荐 16GB |
| 网络 | 需访问 claude.ai (国内用户需特殊配置) |
| 地区 | 必须在 Anthropic 支持的国家/地区 |
| Shell | Bash, Zsh 或 Fish (Windows 用户使用 WSL/Git Bash) |
可选依赖:
- Node.js 18+:仅 NPM 安装方式需要
- ripgrep:通常已包含,如搜索失败需手动安装
重要提示:官方推荐使用 Native 安装方式,无需 Node.js,更稳定。
方法一:Native 安装(推荐)
Native 安装是官方推荐的 Install Claude Code 方法,优势包括:
- ✅ 无需 Node.js依赖
- ✅ 自动更新功能更稳定
- ✅ 一行命令完成安装
- ✅ 支持所有主流操作系统
macOS / Linux / WSL 安装
打开终端,执行:
curl -fsSL https://claude.ai/install.sh | bash
安装过程:
- 下载安装脚本
- 检测系统架构
- 下载对应二进制文件
- 安装到
~/.local/bin/claude - 配置环境变量 (如需要)
Windows PowerShell 安装
以管理员身份打开 PowerShell,执行:
irm https://claude.ai/install.ps1 | iex
Windows CMD 安装
打开命令提示符(CMD),执行:
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
安装特定版本
macOS / Linux / WSL:
# 安装最新版本
curl -fsSL https://claude.ai/install.sh | bash -s latest
# 安装指定版本(例如 1.0.58)
curl -fsSL https://claude.ai/install.sh | bash -s 1.0.58
Windows PowerShell:
# 安装最新版本
& ([scriptblock]::Create((irm https://claude.ai/install.ps1))) latest
# 安装指定版本
& ([scriptblock]::Create((irm https://claude.ai/install.ps1))) 1.0.58
Alpine Linux / musl 系统
apk add libgcc libstdc++ ripgrep
export USE_BUILTIN_RIPGREP=0
curl -fsSL https://claude.ai/install.sh | bash
方法二:Homebrew 安装
macOS 用户可以使用 Homebrew 快速安装:
brew install --cask claude-code
验证安装:
claude --version
更新 Claude Code:
brew upgrade --cask claude-code
卸载:
brew uninstall --cask claude-code
方法三:NPM 安装
⚠️ 警告:NPM 安装是旧方法(Legacy),仅在特定场景使用,推荐迁移到 Native 安装。
安装步骤
- 确认 Node.js 版本:
node --version # 需要 v18.0+
- 全局安装 Claude Code:
npm install -g @anthropic-ai/claude-code
❌ 错误示例(不要这样做):
sudo npm install -g @anthropic-ai/claude-code # 会导致权限问题和安全风险!
从 NPM 迁移到 Native
如果你已经通过 NPM 安装,可以迁移到 Native:
# 卸载 NPM 版本
npm uninstall -g @anthropic-ai/claude-code
# 安装 Native 版本
curl -fsSL https://claude.ai/install.sh | bash
认证与登录
Install Claude Code 后,需要完成认证。Claude Code 提供 3 种认证方式:
方式 1:Claude Console(默认)
- 启动 Claude Code:
cd your-project
claude
- 选择认证方式:
Welcome to Claude Code!
Please login to continue:
1. Claude.ai (Subscription plans)
2. Claude Console (API access with prepaid credits)
Select option [1-2]:
选择选项 2(Console),浏览器会自动打开 OAuth 页面
登录并授权,返回终端即完成
注意事项:
- 需要在 Anthropic Console 激活计费
- 会自动创建 "Claude Code" workspace 用于用量追踪
- 不能为 Claude Code workspace 创建 API 密钥
方式 2:Claude.ai 订阅(Pro/Max)
- 订阅 Claude Pro 或 Max 计划
- 启动 Claude Code 时选择选项 1
- 使用 Claude.ai 账户登录
- 优势:订阅费包含网页版和 CLI 版
价格:
- Pro:$20/月
- Max:$200/月
方式 3:企业平台集成
配置 Claude Code 使用 Amazon Bedrock、Google Vertex AI 或 Microsoft Foundry,适用于企业部署。详见 第三方集成文档。
验证安装
检查版本
claude --version
输出示例:
claude-code version 1.0.58
检查安装类型
claude doctor
输出示例:
Claude Code Diagnostic Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Installation Type: Native
Version: 1.0.58
Node.js: Not required
Auto-update: Enabled
Credentials: Configured
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ Everything looks good!
测试基本功能
cd your-project
claude
> help me understand this codebase
如果 Claude Code 成功响应,则安装完成!
国内用户安装技巧
国内用户在 Install Claude Code 时常遇到网络限制。以下是解决方案:
方案 1:使用 Easy Claude Code 拼车服务(推荐)
优势:
- ✅ 无需 VPN:国内直连,无墙障碍
- ✅ 开箱即用:10 分钟开通
- ✅ 成本低廉:¥399/月起,节省 60%+
安装步骤:
# Step 1: 订阅 Easy Claude Code (https://easyclaude.com)
# Step 2: 获取专属 API Key
# Step 3: 配置环境变量
export ANTHROPIC_AUTH_TOKEN="your-easyclaude-api-key"
export ANTHROPIC_BASE_URL="https://api.easyclaude.com"
# Step 4: 启动 Claude Code
claude
价格对比:
| 方案 | 月费用 | 网络要求 | 稳定性 |
|---|---|---|---|
| Easy Claude Code | ¥399 起 | 无需 VPN | ⭐⭐⭐⭐⭐ |
| Claude 官方 | ¥1,400+ | 需 VPN | ⭐⭐⭐⭐⭐ |
| VPN + 官方 | ¥1,600+ | 不稳定 | ⭐⭐⭐ |
详细对比:Claude Code 价格指南
方案 2:使用 VPN
传统方案,但成本高且不稳定:
# 确保 VPN 已连接
# 直接安装,无需额外配置
curl -fsSL https://claude.ai/install.sh | bash
缺点:
- ❌ VPN 月费 $10-30
- ❌ 网络不稳定
- ❌ 仍需支付官方订阅费
常见问题解决
Q1: 安装后运行 claude 提示 "command not found"
原因:环境变量未配置。
解决方法:
macOS / Linux / WSL:
# 添加到 ~/.bashrc 或 ~/.zshrc
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# 或对于 Zsh
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Windows PowerShell:
# 添加到用户环境变量
$env:PATH += ";$env:USERPROFILE\.local\bin"
Q2: 无法连接到 claude.ai(国内用户)
原因:网络防火墙阻止访问。
解决方法:
- 使用 Easy Claude Code 拼车服务(推荐)
- 使用稳定的 VPN 服务
- 配置 API 中转服务
详细教程:Claude Code 国内使用指南
Q3: WSL 中安装后性能缓慢(Windows 用户)
原因:WSL2 默认内存限制不合理。
解决方法:
创建 ~/.wslconfig 文件(Windows 用户目录):
[wsl2]
memory=8GB
processors=4
重启 WSL:
wsl --shutdown
Q4: npm 安装时出现权限错误
原因:使用了 sudo npm install。
解决方法:
❌ 错误做法:
sudo npm install -g @anthropic-ai/claude-code # 不要这样做!
✅ 正确做法:
# 方法 1: 修复 npm 全局目录权限
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
# 方法 2: 改用 Native 安装(推荐)
curl -fsSL https://claude.ai/install.sh | bash
Q5: 如何卸载 Claude Code?
Native 安装卸载:
macOS / Linux / WSL:
rm -f ~/.local/bin/claude
rm -rf ~/.local/share/claude
# 可选:删除配置文件
rm -rf ~/.claude
rm ~/.claude.json
Windows PowerShell:
Remove-Item -Path "$env:USERPROFILE\.local\bin\claude.exe" -Force
Remove-Item -Path "$env:USERPROFILE\.local\share\claude" -Recurse -Force
# 可选:删除配置文件
Remove-Item -Path "$env:USERPROFILE\.claude" -Recurse -Force
Remove-Item -Path "$env:USERPROFILE\.claude.json" -Force
Homebrew 卸载:
brew uninstall --cask claude-code
NPM 卸载:
npm uninstall -g @anthropic-ai/claude-code
总结
核心要点
通过本 Install Claude Code 指南,你已掌握:
- ✅ 系统要求:macOS/Windows/Linux,最低 4GB 内存
- ✅ 3 种安装方式:Native(推荐)、Homebrew、NPM
- ✅ 认证方法:Console、Claude.ai 订阅、企业平台
- ✅ 验证步骤:
claude --version、claude doctor - ✅ 国内解决方案:Easy Claude Code 拼车服务
- ✅ 常见问题:环境变量、网络、权限、WSL 性能
推荐安装流程
标准用户(国外):
# Step 1: Install
curl -fsSL https://claude.ai/install.sh | bash
# Step 2: Verify
claude --version
# Step 3: Login
claude
国内用户(推荐 Easy Claude Code):
# Step 1: 订阅 https://easyclaude.com
# Step 2: 获取 API Key
# Step 3: 配置
export ANTHROPIC_AUTH_TOKEN="your-key"
export ANTHROPIC_BASE_URL="https://api.easyclaude.com"
# Step 4: Install & Login
curl -fsSL https://claude.ai/install.sh | bash
claude
下一步
相关推荐阅读
关于 Easy Claude Code
Easy Claude Code 是专业的 Claude Code 拼车服务平台,提供从个人到企业的多种套餐。相比官方节省 60%-80% 成本,无需 VPN,10 分钟开通。
拼车价格:
- 💰 小月卡(5人拼车):¥399/月,$20/日额度
- 💰 大月卡(3人拼车):¥799/月,$45/日额度
- 💰 独享卡:¥1,899/月,$110/日额度
Sources:
最后更新时间:2026 年 1 月 7 日