> ## Documentation Index
> Fetch the complete documentation index at: https://code.claude.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 新用户终端指南

> 为首次使用终端的 macOS 和 Windows 用户提供的分步安装 Claude Code 指南。

即使您从未使用过终端，也可以使用 Claude Code。本指南将引导您打开终端、安装 Claude Code 以及进行首次交互。

* [macOS 和 Linux](#macos-and-linux)
* [Windows](#windows)

<Note>
  不想使用终端？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) 或 [Linux](https://claude.com/download?utm_source=claude_code\&utm_medium=docs) 下载，然后查看 [桌面快速入门](/zh-CN/desktop-quickstart) 以开始使用。
</Note>

<h2 id="macos-and-linux">
  macOS 和 Linux
</h2>

按照以下步骤从 macOS 或 Linux 终端安装并启动 Claude Code。Claude Code 需要 macOS 13.0 或更高版本。有关支持的 Linux 发行版，请参阅 [系统要求](/zh-CN/setup#system-requirements)。

<Steps>
  <Step title="打开终端">
    **macOS**：按 `Cmd + Space` 打开 Spotlight 搜索，输入 `Terminal`，然后按 `Enter`。

    **Linux**：打开您的终端应用程序。在大多数发行版上，按 `Ctrl + Alt + T` 或在应用程序菜单中搜索"Terminal"。

    将出现一个带有闪烁光标的窗口。这是您的终端，您可以在其中输入命令。
  </Step>

  <Step title="安装 Claude Code">
    复制此行，将其粘贴到您的终端中（macOS 上按 `Cmd + V`，Linux 上按 `Ctrl + Shift + V`），然后按 `Enter`：

    ```bash theme={null}
    curl -fsSL https://claude.ai/install.sh | bash
    ```

    这将从 claude.ai 下载并运行 Claude Code 安装程序。您将看到文本滚动。完成后，您将看到"Claude Code successfully installed!"。如果您看到错误，请检查下面的 [故障排除部分](#macos-and-linux-troubleshooting)。
  </Step>

  <Step title="启动 Claude Code">
    输入 `claude` 并按 `Enter`：

    ```bash theme={null}
    claude
    ```

    系统将提示您使用 Claude 账户 [登录](/zh-CN/authentication)。按照屏幕上的说明操作。浏览器窗口将打开供您登录。
  </Step>

  <Step title="开始使用 Claude Code">
    登录后，您可以开始向 Claude 提问有关您的代码或其他任何内容的问题。Claude Code 完全以文本形式运行。您输入消息并按 `Enter` 发送。需要了解的几点：

    * 您无法在终端中点击任何内容。使用箭头键移动。
    * 按 `Esc` 中断 Claude（如果它正在运行）。
    * 输入 `exit` 或按 `Ctrl + D` 退出 Claude Code。
    * 输入 `/help` 查看可用命令。
  </Step>
</Steps>

***

<h2 id="windows">
  Windows
</h2>

按照以下步骤在 Windows 上可选地安装 Git for Windows、设置 PowerShell 并启动 Claude Code。Claude Code 需要 Windows 10 版本 1809 或更高版本。有关完整详情，请参阅 [系统要求](/zh-CN/setup#system-requirements)。

<Steps>
  <Step title="为 Windows 安装 Git（可选）">
    Git for Windows 提供 Git Bash，它启用了 Bash 工具。没有它，Claude Code 会改用 PowerShell。您不需要自己学习 Git。

    如果您还没有安装：

    1. 转到 [git-scm.com/downloads/win](https://git-scm.com/downloads/win) 并下载安装程序
    2. 运行安装程序。在每个屏幕上单击"下一步"以接受默认设置。安装程序有很多屏幕，但您不需要更改任何内容。
    3. 如果它要求您选择编辑器，请保持默认值并单击"下一步"。
    4. 当您看到"调整您的 PATH 环境"时，保持推荐选项的选中状态。

    <Note>
      已经有 Git？您可以跳过此步骤。如果您不确定，无论如何都可以安装。重新安装不会导致问题。
    </Note>
  </Step>

  <Step title="打开 PowerShell">
    PowerShell 是 Windows 用于输入命令的内置终端。它预装在每台 Windows 计算机上。

    按 `Win + X` 并从菜单中选择 **Windows PowerShell**（或 **Terminal**）。将出现一个带有闪烁光标的窗口。这是您输入命令的地方。

    <Note>
      Windows 有两个命令行程序：PowerShell 和 CMD。它们看起来相似，但使用不同的命令。确保您在 PowerShell 中进行下一步。

      判断您在哪个程序中的方法：

      * **PowerShell**：在每行的开头显示 `PS C:\Users\YourName>`
      * **CMD**：显示 `C:\Users\YourName>`，没有 `PS`
    </Note>
  </Step>

  <Step title="安装 Claude Code">
    复制此行，使用 `Ctrl + V` 或右键单击将其粘贴到 PowerShell 中，然后按 `Enter`：

    ```powershell theme={null}
    irm https://claude.ai/install.ps1 | iex
    ```

    这将下载并运行 Claude Code 安装程序。`irm` 获取文件，`iex` 运行它。您将看到文本滚动。完成后，您将看到"Claude Code successfully installed!"。如果您看到错误，请检查下面的 [故障排除部分](#windows-troubleshooting)。

    <Note>
      如果您在 CMD 中而不是 PowerShell 中，请使用此命令：

      ```batch theme={null}
      curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
      ```
    </Note>
  </Step>

  <Step title="启动 Claude Code">
    运行 `claude`。如果 PowerShell 显示 `'claude' is not recognized`，则安装目录还不在您的 PATH 中。按照下面的 ['claude is not recognized'](#windows-troubleshooting) 修复，然后打开一个新的 PowerShell 窗口并重试。

    ```powershell theme={null}
    claude
    ```

    系统将提示您使用 Claude 账户 [登录](/zh-CN/authentication)。按照屏幕上的说明操作。浏览器窗口将打开供您登录。
  </Step>

  <Step title="开始使用 Claude Code">
    登录后，您可以开始向 Claude 提问有关您的代码或其他任何内容的问题。Claude Code 完全以文本形式运行。您输入消息并按 `Enter` 发送。需要了解的几点：

    * 您无法在终端中点击任何内容。使用箭头键移动。
    * 按 `Esc` 中断 Claude（如果它正在运行）。
    * 输入 `exit` 或按 `Ctrl + D` 退出 Claude Code。
    * 输入 `/help` 查看可用命令。
  </Step>
</Steps>

***

<h2 id="what’s-next">
  接下来呢？
</h2>

一旦您看到 Claude Code 欢迎屏幕，您就可以开始了。您不需要知道如何编码。用简单的英文描述您想要的内容，Claude 将为您编写代码。

<h3 id="build-something">
  构建项目
</h3>

Claude 可以根据描述创建项目：

```text theme={null}
make me a simple webpage that says hello world
```

Claude 为您创建文件。双击 HTML 文件在浏览器中打开它。

<h3 id="work-with-files-on-your-computer">
  处理计算机上的文件
</h3>

Claude 可以读取和组织您已有的文件：

```text theme={null}
look at the screenshots on my Desktop and rename them based on what's in each image
```

<h3 id="ask-questions">
  提出问题
</h3>

Claude 可以解释事物、帮助您学习或规划项目：

```text theme={null}
I want to build a personal budget tracker. What would I need?
```

如果您还没有项目，没关系。Claude 可以帮助您启动一个新项目。

<h3 id="other-ways-to-use-claude-code">
  使用 Claude Code 的其他方式
</h3>

您不必使用终端。Claude Code 也可在以下位置使用：

* [VS Code](/zh-CN/vs-code) 和 [JetBrains IDEs](/zh-CN/jetbrains) 作为编辑器扩展
* [桌面应用](/zh-CN/desktop-quickstart)，无需终端
* [网络](/zh-CN/claude-code-on-the-web) 在 claude.ai/code 进行云会话
* [GitHub Actions](/zh-CN/github-actions) 和 [GitLab CI/CD](/zh-CN/gitlab-ci-cd) 用于自动化

<h3 id="learn-more">
  了解更多
</h3>

* [快速入门](/zh-CN/quickstart)：Claude Code 首个项目的引导演练
* [Claude Code 如何工作](/zh-CN/how-claude-code-works)：了解 Claude 如何读取文件、运行命令和进行编辑
* [最佳实践](/zh-CN/best-practices)：通过有效的提示和项目设置获得更好的结果
* [常见工作流](/zh-CN/common-workflows)：调试、测试、重构等的分步指南
* [终端配置](/zh-CN/terminal-config)：自定义您的终端以获得最佳的 Claude Code 体验

***

<h2 id="troubleshooting">
  故障排除
</h2>

<h3 id="macos-and-linux-troubleshooting">
  macOS 和 Linux 故障排除
</h3>

如果您在 macOS 或 Linux 上安装时遇到问题，请检查这些常见问题：

<Accordion title="'command not found: claude'">
  如果在安装后看到 `command not found: claude`，安装程序放置 `claude` 的文件夹不在您的 PATH 中。安装程序在安装结束时在 `Setup notes` 下打印了确切的修复方法，所以请运行该命令，或使用下面针对您的 shell 的命令。

  对于 Zsh，macOS 默认 shell：

  ```bash theme={null}
  echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
  source ~/.zshrc
  ```

  对于 Bash，Linux 默认 shell：

  ```bash theme={null}
  echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
  source ~/.bashrc
  ```

  然后打开一个新终端并再次尝试 `claude`。如果仍然找不到，请检查文件 `~/.local/bin/claude` 是否存在。如果不存在，说明安装未完成。有关更多详情，请参阅 [修复您的 PATH](/zh-CN/troubleshoot-install#verify-your-path)。
</Accordion>

<Accordion title="HTML 代码错误或'syntax error near unexpected token'">
  如果您看到 `bash: line 1: syntax error near unexpected token '<'` 或终端中出现 HTML 代码（如 `<!DOCTYPE html>`），安装 URL 返回了网页而不是安装程序脚本。

  如果页面显示"App unavailable in region"，Claude Code 在您的国家/地区不可用。请参阅 [支持的国家/地区](https://www.anthropic.com/supported-countries)。

  否则，请尝试再次运行该命令。如果继续发生，请改用 [Homebrew](https://brew.sh) 安装：

  ```bash theme={null}
  brew install --cask claude-code
  ```
</Accordion>

<Accordion title="'dyld' 错误或'built for Mac OS X 13.0'">
  如果您看到 `dyld: cannot load`、`dyld: Symbol not found` 或 `built for Mac OS X 13.0`，您的 macOS 版本可能比 Claude Code 支持的版本更旧。

  打开 Apple 菜单并选择"关于本机"以检查您的版本。如果它比 13.0 更旧，请通过软件更新更新 macOS。有关更多详情，请参阅 [macOS 故障排除指南](/zh-CN/troubleshoot-install#dyld-cannot-load-on-macos)。
</Accordion>

有关其他错误，请参阅完整的 [安装故障排除指南](/zh-CN/troubleshoot-install)。

<h3 id="windows-troubleshooting">
  Windows 故障排除
</h3>

如果您在 Windows 上安装时遇到问题，请检查这些常见问题：

<Accordion title="'irm is not recognized'">
  您在 CMD 中，而不是 PowerShell。关闭此窗口并改为打开 PowerShell（`Win + X` 然后选择 Windows PowerShell）。

  或者，使用 CMD 安装命令：

  ```batch theme={null}
  curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
  ```
</Accordion>

<Accordion title="SSL/TLS 错误或'Could not create SSL/TLS secure channel'">
  这通常发生在较旧的 Windows 10 系统上。首先运行此行，然后重试安装：

  ```powershell theme={null}
  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  irm https://claude.ai/install.ps1 | iex
  ```
</Accordion>

<Accordion title="'Claude Code on Windows requires either Git for Windows (for bash) or PowerShell'">
  未找到 PowerShell 或 Git Bash。Claude Code 需要至少一个 shell。

  1. 确保 `powershell.exe` 在您的 `PATH` 上。其默认位置是 `C:\Windows\System32\WindowsPowerShell\v1.0\`。或者，安装 [PowerShell 7](https://aka.ms/powershell)，它提供 `pwsh`。
  2. 如果您更愿意使用 Git Bash，请安装 [Git for Windows](https://git-scm.com/downloads/win)，按照 [Windows 部分的第一步](#windows)。
  3. 如果 Git 已安装但 Claude Code 找不到它，请告诉它在哪里查找：
     ```powershell theme={null}
     $env:CLAUDE_CODE_GIT_BASH_PATH="C:\Program Files\Git\bin\bash.exe"
     ```
     然后再次运行 `claude`。如果您的 Git 安装在其他地方，请通过运行以下命令找到路径：
     ```powershell theme={null}
     Get-Command git | Select-Object Source
     ```
     在该路径中查找 `Git\bin` 文件夹并改用它。

  要使其永久化，以便您不必每次都设置它，请参阅 [配置 Git Bash 路径](/zh-CN/troubleshoot-install#claude-code-on-windows-requires-either-git-for-windows-for-bash-or-powershell)。
</Accordion>

<Accordion title="'claude is not recognized'">
  此错误意味着安装目录不在您的 PATH 中。在 PowerShell 中运行这些命令以添加它：

  ```powershell theme={null}
  $currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
  [Environment]::SetEnvironmentVariable('PATH', "$currentPath;$env:USERPROFILE\.local\bin", 'User')
  ```

  关闭 PowerShell，打开一个新窗口，然后再次尝试 `claude`。有关更多详情，请参阅 [验证您的 PATH](/zh-CN/troubleshoot-install#verify-your-path)。
</Accordion>

有关其他错误，请参阅完整的 [安装故障排除指南](/zh-CN/troubleshoot-install)。
