高级设置

Claude Code 的系统要求、特定平台安装、版本管理和卸载。

本页面涵盖系统要求、特定平台安装详情、更新和卸载。有关首次会话的引导式演练,请参阅快速入门。如果您从未使用过终端,请参阅终端指南

系统要求

Claude Code 在以下平台和配置上运行:

  • 操作系统
    • macOS 13.0+
    • Windows 10 1809+ 或 Windows Server 2019+
    • Ubuntu 20.04+
    • Debian 10+
    • Alpine Linux 3.19+
  • 硬件:4 GB+ RAM、x64 或 ARM64 处理器
  • 网络:需要互联网连接。请参阅网络配置
  • Shell:Bash、Zsh、PowerShell 或 CMD。
  • 位置Anthropic 支持的国家/地区

其他依赖项

  • ripgrep:通常包含在 Claude Code 中。如果搜索失败,请参阅搜索故障排除

安装 Claude Code

更喜欢图形界面?[桌面应用](/zh-CN/desktop-quickstart)让您无需使用终端即可使用 Claude Code。下载适用于 [macOS](https://claude.ai/api/desktop/darwin/universal/dmg/latest/redirect?utm_source=claude_code\&utm_medium=docs) 或 [Windows](https://claude.com/download?utm_source=claude_code\&utm_medium=docs) 的版本。

初次使用终端?请参阅终端指南获取分步说明。

To install Claude Code, use one of the following methods:

**macOS, Linux, WSL:**
theme
1
curl -fsSL https://claude.ai/install.sh | bash
**Windows PowerShell:**
theme
1
irm https://claude.ai/install.ps1 | iex
**Windows CMD:**
theme
1
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
If you see `The token '&&' is not a valid statement separator`, you're in PowerShell, not CMD. If you see `'irm' is not recognized as an internal or external command`, you're in CMD, not PowerShell. Your prompt shows `PS C:\` when you're in PowerShell and `C:\` without the `PS` when you're in CMD. [Git for Windows](https://git-scm.com/downloads/win) is recommended on native Windows so Claude Code can use the Bash tool. If Git for Windows is not installed, Claude Code uses PowerShell as the shell tool instead. WSL setups do not need Git for Windows. <Info> Native installations automatically update in the background to keep you on the latest version. </Info>
theme
1
brew install --cask claude-code
Homebrew offers two casks. `claude-code` tracks the stable release channel, which is typically about a week behind and skips releases with major regressions. `claude-code@latest` tracks the latest channel and receives new versions as soon as they ship.

<Info>
  Homebrew installations do not auto-update. Run `brew upgrade claude-code` or `brew upgrade claude-code@latest`, depending on which cask you installed, to get the latest features and security fixes.
</Info>
theme
1
winget install Anthropic.ClaudeCode
<Info>
  WinGet installations do not auto-update. Run `winget upgrade Anthropic.ClaudeCode` periodically to get the latest features and security fixes.
</Info>

You can also install with apt, dnf, or apk on Debian, Fedora, RHEL, and Alpine.

安装完成后,在您要使用的项目中打开终端并启动 Claude Code:

theme
1
claude

如果在安装过程中遇到任何问题,请参阅故障排除安装和登录

在 Windows 上设置

您可以在 Windows 上原生运行 Claude Code,也可以在 WSL 中运行。根据您的项目位置和所需的功能进行选择:

选项 需要 沙箱 何时使用
原生 Windows 无;Git for Windows 是可选的 不支持 Windows 原生项目和工具
WSL 2 WSL 2 已启用 支持 Linux 工具链或沙箱命令执行
WSL 1 WSL 1 已启用 不支持 如果 WSL 2 不可用

选项 1:原生 Windows

从 PowerShell 或 CMD 运行安装命令。您无需以管理员身份运行。安装 Git for Windows 是可选的。它通过提供 Git Bash 来启用 Bash 工具

无论您从 PowerShell 还是 CMD 安装,只会影响您运行的安装命令。您的提示在 PowerShell 中显示为 PS C:\Users\YourName>,在 CMD 中显示为 C:\Users\YourName>(不带 PS)。如果您是终端新手,终端指南会逐步讲解每个步骤。

安装后,从任何终端启动 claude

  • 不使用 Git for Windows,Claude Code 通过 PowerShell 工具运行 shell 命令。

  • 使用 Git for Windows,Claude Code 为 Bash 工具使用 Git Bash。如果 Claude Code 找不到 Git Bash,请在您的 settings.json 文件中设置路径:

    theme
    1
    2
    3
    4
    5
    {
    "env": {
    "CLAUDE_CODE_GIT_BASH_PATH": "C:\\Program Files\\Git\\bin\\bash.exe"
    }
    }

安装 Git for Windows 后,PowerShell 工具正在逐步推出作为 Bash 的额外选项。设置 CLAUDE_CODE_USE_POWERSHELL_TOOL=1 以选择加入或 0 以选择退出。有关设置和限制,请参阅 PowerShell 工具

选项 2:WSL

打开您的 WSL 发行版并从上面的安装说明中运行 Linux 安装程序。您在 WSL 终端内安装和启动 claude,而不是从 PowerShell 或 CMD。

Alpine Linux 和基于 musl 的发行版

Alpine 和其他基于 musl/uClibc 的发行版上的原生安装程序需要 libgcclibstdc++ripgrep。使用您的发行版的包管理器安装这些,然后设置 USE_BUILTIN_RIPGREP=0

此示例在 Alpine 上安装所需的包:

theme
1
apk add libgcc libstdc++ ripgrep

然后在您的 settings.json 文件中将 USE_BUILTIN_RIPGREP 设置为 0

theme
1
2
3
4
5
{
"env": {
"USE_BUILTIN_RIPGREP": "0"
}
}

验证您的安装

安装后,确认 Claude Code 正常工作:

theme
1
claude --version

如果此命令失败并显示 command not found 或其他错误,请参阅排查安装和登录问题

要更详细地检查您的安装和配置,请运行 claude doctor

theme
1
claude doctor

身份验证

Claude Code 需要 Pro、Max、Team、Enterprise 或 Console 账户。免费的 Claude.ai 计划不包括 Claude Code 访问权限。您也可以通过第三方 API 提供商(如 Amazon BedrockGoogle Vertex AIMicrosoft Foundry)使用 Claude Code。

安装后,通过运行 claude 并按照浏览器提示登录。有关所有账户类型和团队设置选项,请参阅身份验证

更新 Claude Code

原生安装会在后台自动更新。您可以配置发布渠道来控制您是立即接收更新还是按延迟的稳定计划接收更新,或者完全禁用自动更新。Homebrew、WinGet 和Linux 包管理器安装默认需要手动更新。

自动更新

Claude Code 在启动时和运行时定期检查更新。更新在后台下载和安装,然后在您下次启动 Claude Code 时生效。

运行 claude doctor 以查看最近一次更新尝试的结果。

如果 npm 全局安装因为 npm 全局目录不可写而无法自动更新,Claude Code 会在启动时显示一次性通知,claude doctor 会列出可用的修复。有关详细信息,请参阅安装期间的权限错误

Homebrew、WinGet、apt、dnf 和 apk 安装默认不会自动更新;请参阅下文以选择加入 Homebrew 和 WinGet。要手动升级 Homebrew,请运行 `brew upgrade claude-code` 或 `brew upgrade claude-code@latest`,具体取决于您安装的 cask。对于 WinGet,请运行 `winget upgrade Anthropic.ClaudeCode`。对于 Linux 包管理器,请参阅[使用 Linux 包管理器安装](#install-with-linux-package-managers)中的升级命令。

要让 Claude Code 在 Homebrew 或 WinGet 上为您运行升级命令,请将 CLAUDE_CODE_PACKAGE_MANAGER_AUTO_UPDATE 设置为 1。Claude Code 随后会在新版本可用时在后台运行升级,并在成功时显示重启提示。升级仅针对 Claude Code 包,不会影响您已安装的其他软件。

在 WinGet 上,当 Claude Code 运行时升级可能会失败,因为 Windows 会锁定可执行文件。在这种情况下,Claude Code 会改为显示手动命令。apt、dnf 和 apk 继续需要手动升级,因为这些命令需要提升的权限。

已知问题:Claude Code 可能会在新版本在这些包管理器中可用之前通知您有更新。如果升级失败,请稍候后重试。

Homebrew 在升级后会在磁盘上保留旧版本。定期运行 brew cleanup 以回收磁盘空间。

配置发布渠道

使用 autoUpdatesChannel 设置控制 Claude Code 为自动更新和 claude update 遵循的发布渠道:

  • "latest",默认值:在新功能发布后立即接收
  • "stable":使用通常约一周前的版本,跳过有重大回归的发布

通过 /config自动更新渠道配置此项,或将其添加到您的 settings.json 文件

theme
1
2
3
{
"autoUpdatesChannel": "stable"
}

对于企业部署,您可以使用托管设置在整个组织中强制执行一致的发布渠道。

Homebrew 安装通过 cask 名称而不是此设置来选择渠道:claude-code 跟踪稳定版,claude-code@latest 跟踪最新版。

固定最低版本

minimumVersion 设置建立了一个下限。后台自动更新和 claude update 拒绝安装低于此值的任何版本,因此如果您已经在较新的 "latest" 构建上,切换到 "stable" 渠道不会降级您。

通过 /config"latest" 切换到 "stable" 会提示您选择保留当前版本或允许降级。选择保留会将 minimumVersion 设置为该版本。切换回 "latest" 会清除它。

将其添加到您的 settings.json 文件以显式固定下限:

theme
1
2
3
4
{
"autoUpdatesChannel": "stable",
"minimumVersion": "2.1.100"
}

托管设置中,这会强制执行用户和项目设置无法覆盖的组织范围最低版本。

禁用自动更新

在您的 settings.json 文件的 env 键中将 DISABLE_AUTOUPDATER 设置为 "1"

theme
1
2
3
4
5
{
"env": {
"DISABLE_AUTOUPDATER": "1"
}
}

DISABLE_AUTOUPDATER 仅停止后台检查;claude updateclaude install 仍然有效。要阻止所有更新路径(包括手动更新),请改为设置 DISABLE_UPDATES。当您通过自己的渠道分发 Claude Code 并需要用户保持在您提供的版本上时,请使用此选项。

手动更新

要立即应用更新而不等待下一次后台检查,请运行:

theme
1
claude update

高级安装选项

这些选项用于版本固定、Linux 包管理器、npm 和验证二进制完整性。

安装特定版本

原生安装程序接受特定版本号或发布渠道(lateststable)。您在安装时选择的渠道将成为自动更新的默认值。有关更多信息,请参阅配置发布渠道

要安装最新版本(默认):

theme
1
curl -fsSL https://claude.ai/install.sh | bash
theme
1
irm https://claude.ai/install.ps1 | iex
theme
1
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

要安装稳定版本:

theme
1
curl -fsSL https://claude.ai/install.sh | bash -s stable
theme
1
& ([scriptblock]::Create((irm https://claude.ai/install.ps1))) stable
theme
1
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd stable && del install.cmd

要安装特定版本号:

theme
1
curl -fsSL https://claude.ai/install.sh | bash -s 2.1.89
theme
1
& ([scriptblock]::Create((irm https://claude.ai/install.ps1))) 2.1.89
theme
1
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd 2.1.89 && del install.cmd

使用 Linux 包管理器安装

Claude Code 发布已签名的 apt、dnf 和 apk 存储库。将 stable 替换为 latest 以使用滚动渠道。包管理器安装不会通过 Claude Code 自动更新;更新通过您的正常系统升级工作流程进行。

所有存储库都使用 Claude Code 发布签名密钥进行签名。在信任密钥之前,请按照每个选项卡中的说明验证它。

适用于 Debian 和 Ubuntu。要使用滚动渠道,请更改 `deb` 行中的两个 `stable` 出现:URL 路径和套件名称。
theme
1
2
3
4
5
6
7
sudo install -d -m 0755 /etc/apt/keyrings
sudo curl -fsSL https://downloads.claude.ai/keys/claude-code.asc \
-o /etc/apt/keyrings/claude-code.asc
echo "deb [signed-by=/etc/apt/keyrings/claude-code.asc] https://downloads.claude.ai/claude-code/apt/stable stable main" \
| sudo tee /etc/apt/sources.list.d/claude-code.list
sudo apt update
sudo apt install claude-code
在信任之前验证 GPG 密钥指纹:`gpg --show-keys /etc/apt/keyrings/claude-code.asc` 应该报告 `31DD DE24 DDFA B679 F42D 7BD2 BAA9 29FF 1A7E CACE`。 要稍后升级,请运行 `sudo apt update && sudo apt upgrade claude-code`。
适用于 Fedora 和 RHEL:
theme
1
2
3
4
5
6
7
8
9
sudo tee /etc/yum.repos.d/claude-code.repo <<'EOF'
[claude-code]
name=Claude Code
baseurl=https://downloads.claude.ai/claude-code/rpm/stable
enabled=1
gpgcheck=1
gpgkey=https://downloads.claude.ai/keys/claude-code.asc
EOF
sudo dnf install claude-code
dnf 在首次安装时下载密钥并提示您确认指纹。在接受之前验证它与 `31DD DE24 DDFA B679 F42D 7BD2 BAA9 29FF 1A7E CACE` 匹配。 要稍后升级,请运行 `sudo dnf upgrade claude-code`。
适用于 Alpine Linux:
theme
1
2
3
4
wget -O /etc/apk/keys/claude-code.rsa.pub \
https://downloads.claude.ai/keys/claude-code.rsa.pub
echo "https://downloads.claude.ai/claude-code/apk/stable" >> /etc/apk/repositories
apk add claude-code
使用 `sha256sum /etc/apk/keys/claude-code.rsa.pub` 验证下载的密钥,应该报告 `395759c1f7449ef4cdef305a42e820f3c766d6090d142634ebdb049f113168b6`。 要稍后升级,请运行 `apk update && apk upgrade claude-code`。

使用 npm 安装

您也可以将 Claude Code 安装为全局 npm 包。该包需要 Node.js 18 或更高版本

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

npm 包安装与独立安装程序相同的原生二进制文件。npm 通过每个平台的可选依赖项(如 @anthropic-ai/claude-code-darwin-arm64)拉取二进制文件,并通过 postinstall 步骤将其链接到位。已安装的 claude 二进制文件本身不调用 Node。

支持的 npm 安装平台是 darwin-arm64darwin-x64linux-x64linux-arm64linux-x64-musllinux-arm64-muslwin32-x64win32-arm64。您的包管理器必须允许可选依赖项。如果安装后二进制文件丢失,请参阅故障排除

要升级 npm 安装,请运行 npm install -g @anthropic-ai/claude-code@latest。避免使用 npm update -g,因为它遵循原始安装的 semver 范围,可能不会将您移动到最新版本。

不要使用 `sudo npm install -g`,因为这可能导致权限问题和安全风险。如果遇到权限错误,请参阅[故障排除权限错误](/zh-CN/troubleshoot-install#permission-errors-during-installation)。

二进制完整性和代码签名

每个发布都发布一个 manifest.json,其中包含每个平台二进制文件的 SHA256 校验和。清单使用 Anthropic GPG 密钥签名,因此验证清单上的签名可以传递地验证它列出的每个二进制文件。

验证清单签名

步骤 1-3 需要带有 gpgcurl 的 POSIX shell。在 Windows 上,在 Git Bash 或 WSL 中运行它们。步骤 4 包括 PowerShell 选项。

发布签名密钥发布在固定 URL。
theme
1
curl -fsSL https://downloads.claude.ai/keys/claude-code.asc | gpg --import
显示导入的密钥的指纹。
theme
1
gpg --fingerprint security@anthropic.com
确认输出包含此指纹:
theme
1
31DD DE24 DDFA B679 F42D  7BD2 BAA9 29FF 1A7E CACE
将 `VERSION` 设置为您要验证的发布。
theme
1
2
3
4
REPO=https://downloads.claude.ai/claude-code-releases
VERSION=2.1.89
curl -fsSLO "$REPO/$VERSION/manifest.json"
curl -fsSLO "$REPO/$VERSION/manifest.json.sig"
针对清单验证分离的签名。
theme
1
gpg --verify manifest.json.sig manifest.json
有效的结果报告 `Good signature from "Anthropic Claude Code Release Signing <security@anthropic.com>"`。 `gpg` 也会为任何新导入的密钥打印 `WARNING: This key is not certified with a trusted signature!`。这是预期的。`Good signature` 行确认密码学检查通过。第 1 步中的指纹比较确认密钥本身是真实的。
将您下载的二进制文件的 SHA256 校验和与 `manifest.json` 中 `platforms..checksum` 下列出的值进行比较。
<Tabs>
  <Tab title="Linux">
    
theme
1
sha256sum claude
</Tab> <Tab title="macOS">
theme
1
shasum -a 256 claude
</Tab> <Tab title="Windows PowerShell">
theme
1
(Get-FileHash claude.exe -Algorithm SHA256).Hash.ToLower()
</Tab> </Tabs>
清单签名可用于 `2.1.89` 及以后的发布。较早的发布在 `manifest.json` 中发布校验和,但没有分离的签名。

平台代码签名

除了签名的清单外,各个二进制文件在支持的地方还带有平台原生代码签名。

  • macOS:由”Anthropic PBC”签名并由 Apple 公证。使用 codesign --verify --verbose ./claude 验证。
  • Windows:由”Anthropic, PBC”签名。使用 Get-AuthenticodeSignature .\claude.exe 验证。
  • Linux:二进制文件不单独进行代码签名。如果您直接从 claude-code-releases 存储桶下载或使用原生安装程序,请使用上面的清单签名验证完整性。如果您使用 apt、dnf 或 apk 安装,您的包管理器会使用存储库签名密钥自动验证签名。

卸载 Claude Code

要删除 Claude Code,请按照您的安装方法的说明进行操作。如果之后 claude 仍然运行,您可能有第二个安装或来自较旧安装程序的遗留 shell 别名。请参阅检查冲突的安装以查找并删除它。

原生安装

删除 Claude Code 二进制文件和版本文件:

theme
1
2
rm -f ~/.local/bin/claude
rm -rf ~/.local/share/claude
theme
1
2
Remove-Item -Path "$env:USERPROFILE\.local\bin\claude.exe" -Force
Remove-Item -Path "$env:USERPROFILE\.local\share\claude" -Recurse -Force

Homebrew 安装

删除您安装的 Homebrew cask。如果您安装了稳定版 cask:

theme
1
brew uninstall --cask claude-code

如果您安装了最新版 cask:

theme
1
brew uninstall --cask claude-code@latest

WinGet 安装

删除 WinGet 包:

theme
1
winget uninstall Anthropic.ClaudeCode

apt / dnf / apk

删除包和存储库配置:

theme
1
2
sudo apt remove claude-code
sudo rm /etc/apt/sources.list.d/claude-code.list /etc/apt/keyrings/claude-code.asc
theme
1
2
sudo dnf remove claude-code
sudo rm /etc/yum.repos.d/claude-code.repo
theme
1
2
3
apk del claude-code
sed -i '\|downloads.claude.ai/claude-code/apk|d' /etc/apk/repositories
rm /etc/apk/keys/claude-code.rsa.pub

npm

删除全局 npm 包:

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

删除配置文件

删除配置文件将删除您的所有设置、允许的工具、MCP 服务器配置和会话历史记录。

VS Code 扩展、JetBrains 插件和桌面应用也会写入 ~/.claude/。如果其中任何一个仍然安装,下次运行时目录会被重新创建。要完全删除 Claude Code,请在删除这些文件之前卸载 VS Code 扩展、JetBrains 插件和桌面应用。

要删除 Claude Code 设置和缓存数据:

theme
1
2
3
4
5
6
7
# 删除用户设置和状态
rm -rf ~/.claude
rm ~/.claude.json

# 删除特定于项目的设置(从您的项目目录运行)
rm -rf .claude
rm -f .mcp.json
theme
1
2
3
4
5
6
7
# 删除用户设置和状态
Remove-Item -Path "$env:USERPROFILE\.claude" -Recurse -Force
Remove-Item -Path "$env:USERPROFILE\.claude.json" -Force

# 删除特定于项目的设置(从您的项目目录运行)
Remove-Item -Path ".claude" -Recurse -Force
Remove-Item -Path ".mcp.json" -Force