Skip to content

安装与环境检查

这一步的目标很简单:你的终端里能跑通 node / npm / claude 三个命令。

1. 检查 Node.js / npm

打开终端运行:

bash
node --version
npm --version

ccodezh 的官方教程要求 Node.js 18+(建议用 20 LTS 更稳)。

2. 安装 Node.js(按你的系统选一种)

Windows

方法一:官方安装包(最省心)

  • 打开 https://nodejs.org/ 下载 LTS(Node.js 20 LTS)
  • 安装时保持默认选项,确保勾选“Add to PATH”

方法二:命令行(推荐 Windows 11 / 新系统)

powershell
winget install OpenJS.NodeJS.LTS

如果你习惯包管理器,也可以用:

powershell
choco install nodejs-lts
# 或
scoop install nodejs-lts

macOS

推荐 Homebrew:

bash
brew install node@20

装完后如果 node 仍找不到,按 Homebrew 的提示把路径加入你的 shell 配置即可。

Linux(以 Ubuntu/Debian 为例)

如果系统仓库版本偏旧,建议用 NodeSource:

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

3. 安装 Claude Code CLI

bash
npm install -g @anthropic-ai/claude-code@latest
claude --version

如果你在国内网络环境下安装很慢,可以临时指定 npm 镜像(可选):

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

4. 首次运行(生成配置目录)

bash
claude

首次运行通常会创建 ~/.claude/ 目录。后续手动配置会用到这个目录。

5. 更新 Claude Code(可选)

bash
claude update

常见安装问题

npm 全局安装提示权限不足(permission denied)

  • Windows:用管理员打开 PowerShell 再重试,或配置 npm 全局目录到用户目录
  • macOS / Linux:建议使用 nvm 管理 Node.js,避免全局权限问题