完整指南
安装 Claude Code,一步一步来
Claude Code 是一个在终端中运行的原生程序 claude。安装程序会将它放在你的主目录中,因此不需要管理员权限,而且它会自动更新。本页的其他方式都是在此基础上的变化:用包管理器代替脚本,用编辑器代替终端,用云账户代替套餐。该用哪个终端运行以及如何设置,见 Claude Code 终端。
安装程序的作用
在 macOS 和 Linux 上,原生安装程序将程序放在 ~/.local/share/claude/versions/ 下,将启动器放在 ~/.local/bin/claude;在 Windows 上,启动器是 %USERPROFILE%\.local\bin\claude.exe。该文件夹必须在 PATH 中。如果安装后找不到 claude,先打开一个新终端:安装时用的终端仍在使用旧 PATH。
Claude Code 在启动时和运行期间检查更新,在后台下载,下次启动时切换到新版本。它保留最新的两个版本,并删除更早的版本。claude update 立即安装更新;claude doctor 显示上次尝试的结果。
latest 或 stable
有两个版本通道。默认通道 latest 会在每个版本发布时立即获取。stable 通常落后一周左右,并跳过存在严重回归问题的版本。在 /config 中选择,或在 settings.json 中设置 autoUpdatesChannel。Homebrew 则根据 cask 名称选择通道:claude-code 跟随 stable,claude-code@latest 跟随 latest。新推出的模型可能需要比 stable 提供的更新的版本。
要从一开始就安装 stable 通道版本,以下依次是在 macOS、Linux 或 WSL 终端中,以及在 Windows PowerShell 中使用的命令:
$ curl -fsSL https://claude.ai/install.sh | bash -s stable
PS> & ([scriptblock]::Create((irm https://claude.ai/install.ps1))) stable
Windows:Claude Code 使用哪个 shell
Claude Code 可以在 Windows 上运行,无需 WSL。没有 Git for Windows 时,它通过 PowerShell 运行 shell 命令。安装 Git for Windows 后,它的 Bash 工具使用 Git Bash,同时仍可使用 PowerShell。如果已安装 Git,但 Claude Code 找不到它,请在 settings.json 的 env 块中将 CLAUDE_CODE_GIT_BASH_PATH 设为 bash.exe 的完整路径。Claude Code 需要 64 位 Windows。
在 WSL 内使用的是 Linux 程序:请在 WSL 终端中安装并启动。项目应放在 Linux 文件系统(/home/)中,而非 /mnt/c/ 下:跨两个文件系统搜索更慢,且可能返回更少的匹配结果。
Linux 软件包仓库
Anthropic 为 Debian、Ubuntu、Fedora、RHEL 和 Alpine 提供经过签名的 apt、dnf 和 apk 仓库,各有 stable 和 latest 渠道。它们通过正常的系统升级更新,不通过 Claude Code 更新。添加签名密钥和仓库文件的命令见 Anthropic 的 设置页面。各发行版的具体说明,以及 Arch、PATH 修复和桌面应用,见 在 Linux 上使用 Claude Code。
更新与卸载
| 安装方式 | Update | 卸载 |
|---|---|---|
| 原生安装程序 | 自动,或 claude update | 删除 ~/.local/bin/claude 和 ~/.local/share/claude |
| Homebrew | brew upgrade claude-code | brew uninstall --cask claude-code |
| WinGet | winget upgrade Anthropic.ClaudeCode | winget uninstall Anthropic.ClaudeCode |
| npm | npm install -g @anthropic-ai/claude-code@latest | npm uninstall -g @anthropic-ai/claude-code |
卸载后,你的设置、MCP 服务器和会话历史仍保留在 ~/.claude 和 ~/.claude.json 中。只有确定不再需要时才删除它们:删除后无法撤销。VS Code 扩展、JetBrains 插件和桌面应用也会写入这些位置,因此要先卸载它们,否则文件夹会重新出现。
会话存储位置
Claude Code 会将每个会话以 JSON lines 格式写入 ~/.claude/projects/,其中包含每次调用的 token 用量,默认在 30 天后删除。Caprock 和其他用量工具读取的就是这些记录:查看方式见 如何查看 Claude Code 用量,各套餐包含的内容见 Claude Code 价格。
常见问题
- Claude Code 免费吗?
- 安装免费,但使用需要付费账户:Pro、Max、Ultra、Team、Enterprise,或按 token 计费的 Claude Console 账户。claude.ai 免费套餐不包含 Claude Code。
- Claude Code 能在 Windows 上运行吗?
- 可以,在 Windows 10 1809 或更高版本上,可原生运行,也可在 WSL 中运行。在 PowerShell 中用 irm https://claude.ai/install.ps1 | iex 安装;Git for Windows 是可选的,可提供 Git Bash。
- 安装 Claude Code 需要 Node.js 吗?
- 不需要。原生安装程序、Homebrew、WinGet 和 Linux 软件包仓库都不需要 Node.js。只有通过 npm 安装才需要 Node.js 22 或更高版本,即便如此,安装后的程序也不使用 Node.js。
- 如何更新 Claude Code?
- 原生安装会在后台自动更新;claude update 可立即应用更新。通过 Homebrew 和 WinGet 安装的版本需要运行 brew upgrade claude-code 或 winget upgrade Anthropic.ClaudeCode。
- 如何卸载 Claude Code?
- 原生安装的程序,删除 ~/.local/bin/claude 和 ~/.local/share/claude。其他安装方式使用 brew uninstall --cask claude-code、winget uninstall Anthropic.ClaudeCode 或 npm uninstall -g @anthropic-ai/claude-code。设置和历史记录会保留在 ~/.claude 中,直到你将其删除。
- 使用 VS Code 扩展需要 CLI 吗?
- 只用聊天面板就不需要:扩展自带一份 CLI。要在编辑器终端中运行 claude,或使用 JetBrains 插件,还需要安装 CLI。
来源
- Claude Code 文档——高级设置(要求、安装、更新、卸载),查阅于 2026年10月3日
- Claude Code 文档——快速入门,查阅于 2026年10月3日
- Claude Code 文档——排查安装和登录问题,查阅于 2026年10月3日
- Claude Code 文档——故障排除,查阅于 2026年10月3日
- Claude Code 文档——身份验证,查阅于 2026年10月3日
- Claude Code 文档——在 VS Code 中使用 Claude Code,查阅于 2026年10月3日
- Claude Code 文档——JetBrains IDE,查阅于 2026年10月3日
- Claude Code 文档——命令(/status、/doctor),查阅于 2026年10月3日
- Claude Code 文档——设置参考(cleanupPeriodDays),查阅于 2026年10月3日
- Claude 套餐和价格,查阅于 2026年10月3日
- Caprock README
试用
记录你运行的每个编程智能体,也包括并非由它启动的会话。免费开源;所有数据都留在你的电脑上。
经过 Apple 公证。同一个文件支持 Apple 芯片和 Intel,适用于 macOS 13 或更高版本。
适用于 Windows 10 22H2 或更高版本,x64。Windows 可能会询问一次是否运行:点击 More info,再点击 Run anyway。
粘贴到 Claude Code、Codex 或任何编程智能体中。
查看它的内容 ▾
Install the Caprock desktop app for me. It is open source (Apache-2.0), a local app for my coding agents: https://github.com/dspv/caprock What the install does and how to remove it: https://github.com/dspv/caprock/blob/master/docs/install-agent.md Run the install script for my system: https://caprock.dev/mac.sh, /win.ps1 or /linux.sh. Read it before you run it if you like. Leave my Claude Code settings alone; the app asks me itself. Tell me when it's open.
或自行运行:
粘贴到 PowerShell:它会为你安装并打开 Caprock。