AI客户端安装流程
# AI客户端安装流程
本文档介绍主流 AI CLI 工具在 macOS 和 Windows 系统上的安装方法。
# 一、Claude Code
Claude Code 是 Anthropic 推出的官方 CLI 工具,让你在终端中与 Claude 对话并执行编码任务。
- 官方网站:https://claude.ai/code (opens new window)
- 官方文档:https://docs.anthropic.com/en/docs/claude-code/overview (opens new window)
- GitHub:https://github.com/anthropics/claude-code (opens new window)
# macOS 安装
# 使用 Homebrew 安装
brew install --cask claude
# 或者使用 npm 安装
npm install -g @anthropic-ai/claude-code
1
2
3
4
5
2
3
4
5
安装完成后,运行以下命令启动:
claude
1
# Windows 安装
# 使用 npm 安装(需要 Node.js 16+)
npm install -g @anthropic-ai/claude-code
1
2
2
或者下载 Windows 安装包:
- 访问 Claude 官网 (opens new window)
- 下载 Windows 安装程序
- 双击安装包按向导完成安装
启动命令:
claude
1
# 配置 API Key
首次运行时需要配置 API Key:
claude config set apiKey sk-ant-xxxxx
1
# 二、OpenAI Codex CLI
Codex 是 OpenAI 推出的 AI 编程助手 CLI 工具。
- 官方网站:https://openai.com/codex (opens new window)
- 官方文档:https://platform.openai.com/docs/guides/codex (opens new window)
- GitHub:https://github.com/openai/codex (opens new window)
# macOS 安装
# 使用 Homebrew 安装
brew install openai-codex
# 或者使用 npm 安装
npm install -g @openai/codex
1
2
3
4
5
2
3
4
5
# Windows 安装
# 使用 npm 安装
npm install -g @openai/codex
1
2
2
# 配置
设置 OpenAI API Key:
# macOS / Linux
export OPENAI_API_KEY="sk-xxxxx"
# Windows PowerShell
$env:OPENAI_API_KEY="sk-xxxxx"
# Windows CMD
set OPENAI_API_KEY=sk-xxxxx
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 三、Google Gemini CLI
Gemini CLI 是 Google 推出的 AI 编程命令行工具。
- 官方网站:https://ai.google.dev/gemini-api/docs/cli (opens new window)
- 官方文档:https://ai.google.dev/gemini-api/docs/cli (opens new window)
- Gemini 开发者平台:https://ai.google.dev/ (opens new window)
# macOS 安装
# 使用 Homebrew 安装
brew install google-gemini
# 或者使用 npm 安装
npm install -g @google/gemini-cli
1
2
3
4
5
2
3
4
5
# Windows 安装
# 使用 npm 安装
npm install -g @google/gemini-cli
1
2
2
# 配置
gemini auth login
1
# 四、常用命令对比
| 客户端 | 启动命令 | 配置方式 |
|---|---|---|
| Claude Code | claude | API Key |
| Codex | codex | API Key |
| Gemini CLI | gemini | OAuth 登录 |
# 五、常见问题
# 1. 权限问题(macOS)
如果遇到权限错误,尝试:
# 修复权限
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
1
2
2
# 2. 命令未找到
确保 npm 全局安装路径已添加到系统 PATH:
# macOS(添加到 ~/.zshrc 或 ~/.bash_profile)
export PATH="$PATH:$(npm config get prefix)/bin"
# Windows(PowerShell)
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$(npm config get prefix)", "User")
1
2
3
4
5
2
3
4
5
# 3. Node.js 版本要求
大多数 AI CLI 工具需要 Node.js 16+:
# 检查 Node 版本
node --version
# 使用 nvm 升级(macOS/Linux)
nvm install 20
nvm use 20
1
2
3
4
5
6
2
3
4
5
6
# 参考链接
编辑 (opens new window)
上次更新: 2026/04/12, 23:32:01