Skip to main content

系统要求与安装

今天聊聊Claude Code的安装。看起来简单,但有些坑需要注意。

系统要求

先确认你的机器满足这些条件:

操作系统

  • macOS:10.15 (Catalina) 或更高版本
  • Linux:Ubuntu 20.04+、Debian 10+ 或其他主流发行版
  • Windows:通过WSL 2 支持

硬件

  • 内存:至少 4GB RAM(推荐 8GB+)
  • 磁盘空间:至少 500MB
  • 处理器:现代多核处理器

软件依赖

  • Node.js:版本 18 或更高(推荐 LTS 版本)
  • npm:随 Node.js 自动安装
  • git:版本 2.23 或更高(可选,但推荐)

检查版本:

node --version
npm --version
git --version

网络要求

  • 稳定的互联网连接
  • 能访问 Anthropic API 服务
  • 国内使用需要配置代理

安装 Node.js

还没装Node.js?按下面步骤来。

macOS

# 使用 Homebrew 安装
brew install node

# 或从官网下载安装包
# https://nodejs.org/

Linux

# Ubuntu/Debian
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

# 或使用 nvm(推荐)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install --lts

Windows (WSL)

# 在 WSL 中使用 nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install --lts

验证安装:

node --version  # 应显示 v18.x.x 或更高
npm --version

安装 Claude Code

全局安装

最简单的方式,全局安装后任何目录都能用:

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

等几分钟就好。

验证安装

claude --version

显示版本号就说明成功了。

查看帮助

claude --help

国内网络环境配置

国内用户需要注意。

使用 npm 镜像源

# 设置淘宝镜像
npm config set registry https://registry.npmmirror.com

# 安装 Claude Code
npm install -g @anthropic-ai/claude-code

# 恢复默认源(可选)
npm config set registry https://registry.npmjs.org

配置代理

有代理的话:

# 设置代理
export HTTP_PROXY=http://your-proxy:port
export HTTPS_PROXY=http://your-proxy:port

# Windows (PowerShell)
$env:HTTP_PROXY="http://your-proxy:port"
$env:HTTPS_PROXY="http://your-proxy:port"

# 安装
npm install -g @anthropic-ai/claude-code

常见问题

权限错误

# macOS/Linux
sudo npm install -g @anthropic-ai/claude-code

# 或修改 npm 全局安装目录(推荐)
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
npm install -g @anthropic-ai/claude-code

网络超时

# 增加超时时间
npm install -g @anthropic-ai/claude-code --timeout=60000

# 或使用代理/镜像源

Node.js 版本过低

# 检查版本
node --version

# 升级
# macOS
brew upgrade node

# 使用 nvm
nvm install --lts
nvm use --lts

找不到 claude 命令

# 检查全局安装路径
npm config get prefix

# 添加到 PATH
echo 'export PATH="$PATH:$(npm config get prefix)/bin"' >> ~/.bashrc
source ~/.bashrc

更新与卸载

更新

# 检查当前版本
claude --version

# 更新
npm update -g @anthropic-ai/claude-code

# 或重新安装
npm install -g @anthropic-ai/claude-code@latest

卸载

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

下一步

安装完成后:

  1. 注册 Anthropic 账号并认证
  2. 了解基本使用方法
  3. 探索核心功能

参考资源