Claude Code 安裝指南

本指南詳細介紹 Claude Code 在各平台上的安裝、配置和更新方法。

系統要求

Claude Code 支援以下作業系統和配置:

元件要求
作業系統macOS 13.0+、Windows 10 1809+ 或 Windows Server 2019+、Ubuntu 20.04+、Debian 10+、Alpine Linux 3.19+
記憶體4 GB 以上
網路需要網際網路連線
ShellBash、Zsh、PowerShell 或 CMD
地區Anthropic 支援的國家和地區

額外依賴

  • ripgrep:通常隨 Claude Code 一起提供,如果搜尋失敗請參閱故障排除部分。

安裝方法

方法一:原生安裝(推薦)

macOS、Linux、WSL:

curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell:

irm https://claude.ai/install.ps1 | iex

Windows CMD:

curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

注意:Windows 需要先安裝 Git for Windows。

原生安裝會自動在背景更新到最新版本。

方法二:Homebrew(macOS/Linux)

brew install --cask claude-code

Homebrew 安裝不會自動更新,需要定期執行 brew upgrade claude-code 取得最新功能和安全修復。

方法三:WinGet(Windows)

winget install Anthropic.ClaudeCode

WinGet 安裝不會自動更新,需要定期執行 winget upgrade Anthropic.ClaudeCode 進行手動更新。

驗證安裝

安裝完成後,確認 Claude Code 正常運作:

claude --version

如需更詳細的安裝和配置檢查,可以執行:

claude doctor

帳戶認證

Claude Code 需要 Pro、Max、Teams、Enterprise 或 Console 帳戶。免費 Claude.ai 方案不包含 Claude Code 存取權限。

安裝完成後,執行 claude 命令並按照瀏覽器提示登入即可。

更新 Claude Code

自動更新

原生安裝的 Claude Code 會在啟動時和執行期間定期檢查更新。更新會在背景下載安裝,下次啟動 Claude Code 時生效。

可以透過配置發布頻道來控制更新時機:

  • latest(預設):立即接收新功能
  • stable:使用大約一週前的版本,跳過有重大問題的版本

在設定檔案中配置:

{
  "autoUpdatesChannel": "stable"
}

停用自動更新

在設定檔案中設定環境變數:

{
  "env": {
    "DISABLE_AUTOUPDATER": "1"
  }
}

手動更新

立即套用更新而不等待背景檢查:

claude update

Homebrew 和 WinGet 安裝需要手動更新:

  • Homebrew:brew upgrade claude-code
  • WinGet:winget upgrade Anthropic.ClaudeCode

進階安裝選項

安裝指定版本

安裝最新版本:

curl -fsSL https://claude.ai/install.sh | bash

安裝穩定版本:

curl -fsSL https://claude.ai/install.sh | bash -s stable

安裝特定版本號(如 1.0.58):

curl -fsSL https://claude.ai/install.sh | bash -s 1.0.58

從 npm 遷移到原生安裝

如果你之前用 npm 安裝過 Claude Code,可以遷移到原生安裝:

# 安裝原生二進制
curl -fsSL https://claude.ai/install.sh | bash

# 移除舊的 npm 安裝
npm uninstall -g @anthropic-ai/claude-code

廢棄的 npm 安裝方式

npm 安裝方式已廢棄。如果確實需要使用 npm 安裝,必須先安裝 Node.js 18+:

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

注意:不要使用 sudo npm install -g,這會導致權限問題和安全風險。

解除安裝 Claude Code

原生安裝解除安裝

macOS、Linux、WSL:

rm -f ~/.local/bin/claude
rm -rf ~/.local/share/claude

Windows PowerShell:

Remove-Item -Path "$env:USERPROFILE\.local\bin\claude.exe" -Force
Remove-Item -Path "$env:USERPROFILE\.local\share\claude" -Recurse -Force

Homebrew 解除安裝

brew uninstall --cask claude-code

WinGet 解除安裝

winget uninstall Anthropic.ClaudeCode

npm 解除安裝

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

移除設定檔

警告:移除設定檔將刪除所有設定、允許的工具、MCP 伺服器配置和會話歷史。

macOS、Linux、WSL:

# 移除使用者設定和狀態
rm -rf ~/.claude
rm ~/.claude.json

# 移除專案特定設定(從專案目錄執行)
rm -rf .claude
rm -f .mcp.json

Windows PowerShell:

# 移除使用者設定和狀態
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

Windows 特殊配置

Claude Code 在 Windows 上需要 Git for Windows 或 WSL。可以從 PowerShell、CMD 或 Git Bash 啟動 claude。

如果 Claude Code 找不到 Git Bash 安裝位置,可以在設定檔案中配置路徑:

{
  "env": {
    "CLAUDE_CODE_GIT_BASH_PATH": "C:\\Program Files\\Git\\bin\\bash.exe"
  }
}

Alpine Linux 配置

在 Alpine 和其他 musl/uClibc 發行版上,原生安裝程式需要 libgcc、libstdc++ 和 ripgrep。先使用套件管理器安裝這些依賴,然後設定 USE_BUILTIN_RIPGREP=0。

在 Alpine 上安裝所需套件:

apk add libgcc libstdc++ ripgrep

然後在設定檔案中配置:

{
  "env": {
    "USE_BUILTIN_RIPGREP": "0"
  }
}

二進制完整性驗證

可以透過 SHA256 驗證碼驗證 Claude Code 二進制的完整性。驗證碼發布在發布清單中,網址格式為: https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/{VERSION}/manifest.json

簽名二進制發布在以下平台:

  • macOS:由 "Anthropic PBC" 簽名並經過 Apple 公證
  • Windows:由 "Anthropic, PBC" 簽名