> ## Documentation Index
> Fetch the complete documentation index at: https://dify-6c0370d8-docs-new-agent-experience.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 安装 difyctl

> 用一行脚本或手动下载二进制文件安装 difyctl

> 本文档由 AI 自动翻译。如有任何不准确之处，请参考 [英文原版](/en/cli/install)。

`difyctl` 是一个独立的二进制文件，无任何运行时依赖。安装脚本会检测你的平台，从 Dify 的 GitHub Releases 下载匹配的构建版本，校验其校验和，并完成安装。

<Note>
  `difyctl` 需要 Dify 1.15.0 或更高版本。
</Note>

## 安装

<Steps>
  <Step title="运行安装程序">
    每个 Dify 发布版本都会随附一个 `difyctl` 构建版本，安装程序默认获取最新版本。

    <Tabs>
      <Tab title="macOS / Linux">
        支持的平台：macOS 和 Linux，x64 和 arm64。

        ```bash theme={null}
        curl -fsSL https://raw.githubusercontent.com/langgenius/dify/main/cli/scripts/install-cli.sh | sh
        ```

        脚本会安装到 `~/.local/bin/difyctl`，并在该目录不在你的 `PATH` 中时提示你。
      </Tab>

      <Tab title="Windows">
        支持的平台：x64。

        ```powershell theme={null}
        irm https://raw.githubusercontent.com/langgenius/dify/main/cli/scripts/install.ps1 | iex
        ```

        脚本会安装到 `%LOCALAPPDATA%\difyctl\bin\difyctl.exe`，如果该目录尚未加入 `PATH`，会打印将其加入 `PATH` 的命令。
      </Tab>

      <Tab title="手动下载">
        1. 从 [Dify 的 GitHub Releases](https://github.com/langgenius/dify/releases) 中，选择与服务器 Dify 版本匹配的发布版本，并下载两个资源文件：

           * 适用于你平台的二进制文件（`difyctl-v<version>-<os>-<arch>`）
           * 校验和清单（`difyctl-v<version>-checksums.txt`）

        2. 计算二进制文件的 SHA-256 哈希值，并与 checksums 文件中对应的条目比对。

           如果两者不一致，说明下载文件已损坏或被篡改；删除它并重新下载。

                   <CodeGroup>
                     ```bash macOS / Linux theme={null}
                     shasum -a 256 difyctl-v<version>-<os>-<arch>
                     ```

                     ```powershell Windows theme={null}
                     Get-FileHash difyctl-v<version>-windows-x64.exe
                     ```
                   </CodeGroup>

        3. 将二进制文件加入 `PATH`：

                   <CodeGroup>
                     ```bash macOS / Linux theme={null}
                     chmod +x difyctl-v<version>-<os>-<arch>
                     mv difyctl-v<version>-<os>-<arch> ~/.local/bin/difyctl
                     ```

                     ```powershell Windows theme={null}
                     New-Item -ItemType Directory -Force "$env:LOCALAPPDATA\difyctl\bin" | Out-Null
                     Move-Item difyctl-v<version>-windows-x64.exe "$env:LOCALAPPDATA\difyctl\bin\difyctl.exe"
                     ```
                   </CodeGroup>
      </Tab>
    </Tabs>

    <Tip>
      如需自定义安装，可在运行安装命令时设置以下环境变量。

      | 变量                | 说明                                                                                                                                           | 示例            |
      | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
      | `DIFY_VERSION`    | 用于安装 `difyctl` 的 Dify 发布标签，取自 [Dify Releases](https://github.com/langgenius/dify/releases)。<br /><br />默认使用最新发布版本；当服务器不是最新版本时，将其设置为服务器的发布标签。 | `1.15.0`      |
      | `DIFYCTL_VERSION` | 固定使用特定的 `difyctl` 构建版本。仅在未设置 `DIFY_VERSION` 时生效。                                                                                             | `0.1.0-alpha` |
      | `DIFYCTL_PREFIX`  | 安装目录（默认 `~/.local`）。二进制文件会放在 `<prefix>/bin` 下。                                                                                               | `/usr/local`  |

      例如：

      <CodeGroup>
        ```bash macOS / Linux theme={null}
        curl -fsSL https://raw.githubusercontent.com/langgenius/dify/main/cli/scripts/install-cli.sh | DIFY_VERSION=1.15.0 sh
        ```

        ```powershell Windows theme={null}
        # PowerShell 没有内联写法，该设置在当前会话剩余时间内生效
        $env:DIFY_VERSION = "1.15.0"
        irm https://raw.githubusercontent.com/langgenius/dify/main/cli/scripts/install.ps1 | iex
        ```
      </CodeGroup>
    </Tip>
  </Step>

  <Step title="验证安装">
    ```bash theme={null}
    difyctl version
    ```

    你应当看到一个 `Client:` 区块，其中包含版本和平台信息。

    如果你看到的是 `command not found`，说明安装目录不在你的 `PATH` 中。将它加入：

    <CodeGroup>
      ```bash macOS / Linux theme={null}
      # add to ~/.zshrc or ~/.bashrc; running it inline only lasts until the session ends
      export PATH="$HOME/.local/bin:$PATH"
      ```

      ```powershell Windows theme={null}
      [Environment]::SetEnvironmentVariable('PATH', "$env:LOCALAPPDATA\difyctl\bin;$env:PATH", 'User')
      ```
    </CodeGroup>
  </Step>
</Steps>

## 更新

要更新 `difyctl`，重新运行安装脚本即可，它会原地替换二进制文件。要切换到特定的 Dify 版本，按上文设置 `DIFY_VERSION`。

## 卸载

<CodeGroup>
  ```bash macOS / Linux theme={null}
  rm ~/.local/bin/difyctl
  ```

  ```powershell Windows theme={null}
  Remove-Item -Recurse "$env:LOCALAPPDATA\difyctl"
  ```
</CodeGroup>

要在卸载前退出登录，运行 [`difyctl auth logout`](/zh/cli/reference/auth-and-contexts#退出登录)。

## 后续步骤

装好 `difyctl` 后，前往 [快速开始](/zh/cli/quick-start) 登录并运行你的第一个应用。
