# 将 Flutter 添加到 PATH

> 了解在下载 Flutter SDK 后如何将 Flutter 添加到你的 PATH。



Learn how to add Flutter to your `PATH` environment variable
after downloading the SDK.
Adding Flutter to your `PATH` allows you to use the
`flutter` and `dart` command-line tools in terminals and IDEs.

了解如何在下载 SDK 后将 Flutter 添加到你的 `PATH` 环境变量。
将 Flutter 添加到你的 `PATH` 后，你就可以在终端和 IDE 中使用
`flutter` 和 `dart` 命令行工具。

:::tip
If you haven't downloaded Flutter yet,
follow [Set up and test drive Flutter][] instead.

如果你尚未下载 Flutter，
请先按照 [设置并试跑 Flutter][Set up and test drive Flutter] 进行操作。
:::

[Set up and test drive Flutter]: /install/quick

<div class="card-grid">
  <a class="card outlined-card" href="#windows">
    <div class="card-header">
      <span class="card-title">Windows</span>
    </div>
    <div class="card-content">
      <p>Add Flutter to your path on Windows.</p>
      <p>在 Windows 上将 Flutter 添加到你的 `PATH`。</p>
    </div>
  </a>
  <a class="card outlined-card" href="#macos">
    <div class="card-header">
      <span class="card-title">macOS</span>
    </div>
    <div class="card-content">
      <p>Add Flutter to your path on macOS.</p>
      <p>在 macOS 上将 Flutter 添加到你的 `PATH`。</p>
    </div>
  </a>
  <a class="card outlined-card" href="#linux">
    <div class="card-header">
      <span class="card-title">Linux</span>
    </div>
    <div class="card-content">
      <p>Add Flutter to your path on Linux.</p>
      <p>在 Linux 上将 Flutter 添加到你的 `PATH`。</p>
    </div>
  </a>
  <a class="card outlined-card" href="#chromeos">
    <div class="card-header">
      <span class="card-title">ChromeOS</span>
    </div>
    <div class="card-content">
      <p>Add Flutter to your path on ChromeOS.</p>
      <p>在 ChromeOS 上将 Flutter 添加到你的 `PATH`。</p>
    </div>
  </a>
</div>

## Windows

To run `flutter` and `dart` commands in a terminal on Windows,
add the Flutter SDK's `bin` directory to the `Path` environment variable.

要在 Windows 终端中运行 `flutter` 和 `dart` 命令，
请将 Flutter SDK 的 `bin` 目录添加到 `Path` 环境变量。


 1. <h3>Determine your Flutter SDK installation location</h3>

    <h3>确定 Flutter SDK 安装位置</h3>

    Copy the absolute path to the directory that you
    downloaded and extracted the Flutter SDK into.

    复制你下载并解压 Flutter SDK 所在目录的绝对路径。

 1. <h3>Navigate to the environment variables settings</h3>

    <h3>进入环境变量设置</h3>

    1. Press <kbd>Windows</kbd> + <kbd>Pause</kbd>.

       按下快捷键 <kbd>Windows</kbd> + <kbd>Pause</kbd>。

       If your keyboard lacks a <kbd>Pause</kbd> key,
       try <kbd>Windows</kbd> + <kbd>Fn</kbd> + <kbd>B</kbd>.

       如果你的键盘上没有 <kbd>Pause</kbd> 键，
       请尝试 <kbd>Windows</kbd> + <kbd>Fn</kbd> + <kbd>B</kbd>。

       The **System > About** dialog opens.

       这将会显示 **系统 > 系统信息** 的窗口。

    1. Click **Advanced System Settings**
       <span aria-label="and then">></span> **Advanced**
       <span aria-label="and then">></span> **Environment Variables...**.

       单击 **高级系统设置**
       <span aria-label="and then">></span> **高级**
       <span aria-label="and then">></span> **环境变量…**

       The **Environment Variables** dialog opens.

       这将会显示 **环境变量** 的窗口。

 1. <h3>Add the Flutter SDK bin to your path</h3>

    <h3>将 Flutter SDK 的 bin 添加到你的 PATH</h3>

    1. In the **User variables for (username)** section
       of the **Environment Variables** dialog,
       look for the **Path** entry.

       在 **环境变量** 对话框的 **（用户名）的用户变量** 区域中，
       查找 **Path** 条目。

    1. If the **Path** entry exists, double-click it.

       若 **Path** 条目已存在，请双击它。

       The **Edit Environment Variable** dialog should open.

       此时应会打开 **编辑环境变量** 对话框。

       1. Double-click inside an empty row.

          双击空白行。

       1. Type the path to the `bin` directory of your Flutter installation.

          输入 Flutter 安装目录下 `bin` 的路径。

          For example, if you downloaded Flutter into a
          `develop\flutter` folder inside your user directory,
          you'd type the following:

          例如，若你将 Flutter 下载到用户目录下的
          `develop\flutter` 文件夹，则应输入：

          ```plaintext
          %USERPROFILE%\develop\flutter\bin
          ```

       1. Click the Flutter entry you added to select it.

          点击你添加的 Flutter 条目以将其选中。

       1. Click **Move Up** until the Flutter entry sits at the top of the list.

          点击 **上移**，直到 Flutter 条目位于列表顶部。

       1. To confirm your changes, click **OK** three times.

          要确认更改，请点击三次 **确定**。

       {: type="a"}

    1. If the entry doesn't exist, click **New...**.

       若该条目不存在，请点击 **新建…**。

       The **Edit Environment Variable** dialog should open.

       此时应会打开 **编辑环境变量** 对话框。

       1. In the **Variable Name** box, type `Path`.

          在 **变量名** 框中输入 `Path`。

       1. In the **Variable Value** box,
          type the path to the `bin` directory of your Flutter installation.

          在 **变量值** 框中，
          输入 Flutter 安装目录下 `bin` 的路径。

          For example, if you downloaded Flutter into a
          `develop\flutter` folder inside your user directory,
          you'd type the following:

          例如，若你将 Flutter 下载到用户目录下的
          `develop\flutter` 文件夹，则应输入：

          ```plaintext
          %USERPROFILE%\develop\flutter\bin
          ```

       1. To confirm your changes, click **OK** three times.

          要确认更改，请点击三次 **确定**。

       {: type="a"}

 1. <h3>Apply your changes</h3>

    <h3>应用你的更改</h3>

    To apply this change and get access to the `flutter` tool,
    close and reopen all open command prompts,
    sessions in your terminal apps, and IDEs.

    要应用此更改并访问 `flutter` 工具，
    请关闭并重新打开所有已打开的命令提示符、
    终端应用中的会话以及 IDE。

 1. <h3>Validate your setup</h3>

    <h3>验证你的配置</h3>

    To ensure you successfully added the SDK to your `PATH`,
    open command prompt or your preferred terminal app,
    then try running the `flutter` and `dart` tools.

    为确保你已成功将 SDK 添加到 `PATH`，
    请打开命令提示符或你偏好的终端应用，
    然后尝试运行 `flutter` 和 `dart` 工具。

    ```console
    $ flutter --version
    $ dart --version
    ```

    If either command isn't found,
    check out [Flutter installation troubleshooting][troubleshoot].

    若任一命令未找到，
    请参阅 [Flutter 安装问题排查][troubleshoot]。

{: .steps}

[troubleshoot]: /install/troubleshoot


## macOS

To run `flutter` and `dart` commands in a terminal on macOS,
add the Flutter SDK's `bin` directory to the `PATH` environment variable.

要在 macOS 终端中运行 `flutter` 和 `dart` 命令，
请将 Flutter SDK 的 `bin` 目录添加到 `PATH` 环境变量。

:::note
The following steps assume you're
using the [default shell][zsh-mac] on macOS, Zsh.

以下步骤假定你在 macOS 上使用
[默认 shell][zsh-mac] Zsh。

If you use another shell besides Zsh,
check out [this tutorial on setting your PATH][other-path].

若你使用的不是 Zsh，
请参阅 [这篇设置 PATH 的教程][other-path]。
:::

 1. <h3>Determine your Flutter SDK installation location</h3>

    <h3>确定 Flutter SDK 安装位置</h3>

    Copy the absolute path to the directory that you
    downloaded and extracted the Flutter SDK into.

    复制你下载并解压 Flutter SDK 所在目录的绝对路径。

 1. <h3>Open or create the Zsh environment variable file</h3>

    <h3>打开或创建 Zsh 环境变量文件</h3>

    If it exists, open the [Zsh environment variable file][zsh-files]
    `~/.zprofile` in your preferred text editor.
    If it doesn't exist, create the `~/.zprofile` file.

    若存在，请在你偏好的文本编辑器中打开
    [Zsh 环境变量文件][zsh-files] `~/.zprofile`。
    若不存在，请创建 `~/.zprofile` 文件。

 1. <h3>Add the Flutter SDK bin to your path</h3>

    <h3>将 Flutter SDK 的 bin 添加到你的 PATH</h3>

    At the end of your `~/.zprofile` file,
    use the built-in `export` command to update the `PATH` variable
    to include the `bin` directory of your Flutter installation.

    在 `~/.zprofile` 文件末尾，
    使用内置 `export` 命令更新 `PATH` 变量，
    使其包含 Flutter 安装目录下的 `bin`。

    Replace `<path-to-sdk>` with the path to your Flutter SDK installation.

    将 `<path-to-sdk>` 替换为你的 Flutter SDK 安装路径。

    ```bash
    export PATH="<path-to-sdk>/bin:$PATH"
    ```

    For example, if you downloaded Flutter into a
    `develop/flutter` folder inside your user directory,
    you'd add the following to the file:

    例如，若你将 Flutter 下载到用户目录下的
    `develop/flutter` 文件夹，可向文件添加：

    ```bash
    export PATH="$HOME/develop/flutter/bin:$PATH"
    ```

 1. <h3>Save your changes</h3>

    <h3>保存你的更改</h3>

    Save, then close, the `~/.zprofile` file you edited.

    保存并关闭你编辑的 `~/.zprofile` 文件。

 1. <h3>Apply your changes</h3>

    <h3>应用你的更改</h3>

    To apply this change and get access to the `flutter` tool,
    close and reopen all open Zsh sessions in your terminal apps and IDEs.

    要应用此更改并访问 `flutter` 工具，
    请在终端应用和 IDE 中关闭并重新打开所有已打开的 Zsh 会话。

 1. <h3>Validate your setup</h3>

    <h3>验证你的配置</h3>

    To ensure you successfully added the SDK to your `PATH`,
    open a Zsh session in your preferred terminal,
    then try running the `flutter` and `dart` tools.

    为确保你已成功将 SDK 添加到 `PATH`，
    请在你偏好的终端中打开 Zsh 会话，
    然后尝试运行 `flutter` 和 `dart` 工具。

    ```console
    $ flutter --version
    $ dart --version
    ```

    If either command isn't found,
    check out [Flutter installation troubleshooting][troubleshoot].

    若任一命令未找到，
    请参阅 [Flutter 安装问题排查][troubleshoot]。

{: .steps}

[zsh-mac]: https://support.apple.com/en-us/102360
[zsh-files]: https://zsh.sourceforge.io/Intro/intro_3.html
[other-path]: https://www.cyberciti.biz/faq/unix-linux-adding-path/
[troubleshoot]: /install/troubleshoot


## Linux

## Linux

To run `flutter` and `dart` commands in a terminal on Linux,
add the Flutter SDK's `bin` directory to the `PATH` environment variable.

要在 Linux 终端中运行 `flutter` 和 `dart` 命令，
请将 Flutter SDK 的 `bin` 目录添加到 `PATH` 环境变量。

 1. <h3>Determine your Flutter SDK installation location</h3>

    <h3>确定 Flutter SDK 安装位置</h3>

    Copy the absolute path to the directory that you
    downloaded and extracted the Flutter SDK into.

    复制你下载并解压 Flutter SDK 所在目录的绝对路径。

 1. <h3>Determine your default shell</h3>

    <h3>确定你的默认 shell</h3>

    If you don't know what shell you use,
    check which shell starts when you open a new console window.

    若你不确定自己使用哪种 shell，
    可查看打开新控制台窗口时启动的是哪一种。

    ```console
    $ echo $SHELL
    ```

 1. <h3>Add the Flutter SDK bin to your path</h3>

    <h3>将 Flutter SDK 的 bin 添加到你的 PATH</h3>

    To add the `bin` directory of your Flutter installation to your `PATH`:

    要将 Flutter 安装目录下的 `bin` 添加到 `PATH`：

    1. Expand the instructions for your default shell.

       展开与你默认 shell 对应的说明。

    1. Copy the provided command.

       复制提供的命令。

    1. Replace `<path-to-sdk>` with the path to your Flutter SDK install.

       将 `<path-to-sdk>` 替换为你的 Flutter SDK 安装路径。

    1. Run the edited command in your preferred terminal with that shell.

       在使用该 shell 的你偏好的终端中运行编辑后的命令。

    <hr>

    <details>
    <summary>展开 <code>bash</code> 相关说明</summary>

    ```console
    $ echo 'export PATH="<path-to-sdk>/bin:$PATH"' >> ~/.bashrc
    ```

    For example, if you downloaded Flutter into a
    `develop/flutter` folder inside your user directory,
    you'd run the following:

    例如，若你将 Flutter 下载到用户目录下的
    `develop/flutter` 文件夹，可运行：

    ```console
    $ echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.bashrc
    ```

    </details>

    <details>
    <summary>展开 <code>zsh</code> 相关说明</summary>

    ```console
    $ echo 'export PATH="<path-to-sdk>/bin:$PATH"' >> ~/.zshenv
    ```

    For example, if you downloaded Flutter into a
    `develop/flutter` folder inside your user directory,
    you'd run the following:

    例如，若你将 Flutter 下载到用户目录下的
    `develop/flutter` 文件夹，可运行：

    ```console
    $ echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.zshenv
    ```

    </details>

    <details>
    <summary>展开 <code>fish</code> 相关说明</summary>

    ```console
    $ fish_add_path -g -p <path-to-sdk>/bin
    ```

    For example, if you downloaded Flutter into a
    `develop/flutter` folder inside your user directory,
    you'd run the following:

    例如，若你将 Flutter 下载到用户目录下的
    `develop/flutter` 文件夹，可运行：

    ```console
    $ fish_add_path -g -p ~/develop/flutter/bin
    ```

    </details>

    <details>
    <summary>展开 <code>csh</code> 相关说明</summary>

    ```console
    $ echo 'setenv PATH "<path-to-sdk>/bin:$PATH"' >> ~/.cshrc
    ```

    For example, if you downloaded Flutter into a
    `develop/flutter` folder inside your user directory,
    you'd run the following:

    例如，若你将 Flutter 下载到用户目录下的
    `develop/flutter` 文件夹，可运行：

    ```console
    $ echo 'setenv PATH "$HOME/develop/flutter/bin:$PATH"' >> ~/.cshrc
    ```

    </details>

    <details>
    <summary>展开 <code>tcsh</code> 相关说明</summary>

    ```console
    $ echo 'setenv PATH "<path-to-sdk>/bin:$PATH"' >> ~/.tcshrc
    ```

    For example, if you downloaded Flutter into a
    `develop/flutter` folder inside your user directory,
    you'd run the following:

    例如，若你将 Flutter 下载到用户目录下的
    `develop/flutter` 文件夹，可运行：

    ```console
    $ echo 'setenv PATH "$HOME/develop/flutter/bin:$PATH"' >> ~/.tcshrc
    ```

    </details>

    <details>
    <summary>展开 <code>ksh</code> 相关说明</summary>

    ```console
    $ echo 'export PATH="<path-to-sdk>/bin:$PATH"' >> ~/.profile
    ```

    For example, if you downloaded Flutter into a
    `develop/flutter` folder inside your user directory,
    you'd run the following:

    例如，若你将 Flutter 下载到用户目录下的
    `develop/flutter` 文件夹，可运行：

    ```console
    $ echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.profile
    ```

    </details>

    <details>
    <summary>展开 <code>sh</code> 相关说明</summary>

    ```console
    $ echo 'export PATH="<path-to-sdk>/bin:$PATH"' >> ~/.profile
    ```

    For example, if you downloaded Flutter into a
    `develop/flutter` folder inside your user directory,
    you'd run the following:

    例如，若你将 Flutter 下载到用户目录下的
    `develop/flutter` 文件夹，可运行：

    ```console
    $ echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.profile
    ```

    </details>

 1. <h3>Apply your changes</h3>

    <h3>应用你的更改</h3>

    To apply this change and get access to the `flutter` tool,
    close and reopen all open shell sessions in your terminal apps and IDEs.

    要应用此更改并访问 `flutter` 工具，
    请在终端应用和 IDE 中关闭并重新打开所有已打开的 shell 会话。

 1. <h3>Validate your setup</h3>

    <h3>验证你的配置</h3>

    To ensure you successfully added the SDK to your `PATH`,
    open your preferred terminal with your default shell,
    then try running the `flutter` and `dart` tools.

    为确保你已成功将 SDK 添加到 `PATH`，
    请使用默认 shell 打开你偏好的终端，
    然后尝试运行 `flutter` 和 `dart` 工具。

    ```console
    $ flutter --version
    $ dart --version
    ```

    If either command isn't found,
    check out [Flutter installation troubleshooting][troubleshoot].

    若任一命令未找到，
    请参阅 [Flutter 安装问题排查][troubleshoot]。

{: .steps}

[troubleshoot]: /install/troubleshoot


## ChromeOS

To run `flutter` and `dart` commands in a terminal on chromeOS,
add the Flutter SDK's `bin` directory to the `PATH` environment variable.

要在 ChromeOS 终端中运行 `flutter` 和 `dart` 命令，
请将 Flutter SDK 的 `bin` 目录添加到 `PATH` 环境变量。

:::note
The following steps assume
you've already [turned on Linux support][chromeos-linux] and that
you're using Bash or the default shell on ChromeOS.

以下步骤假定
你已 [开启 Linux 支持][chromeos-linux]，并且
你使用的是 ChromeOS 上的 Bash 或默认 shell。

If you're using a different shell besides the default or Bash, follow the
[add to path instructions for Linux][linux-path]{: target="_blank"} instead.

若你使用的不是默认 shell 或 Bash，请改为按照
[Linux 的添加到 PATH 说明][linux-path]{: target="_blank"} 操作。
:::

 1. <h3>Determine your Flutter SDK installation location</h3>

    <h3>确定 Flutter SDK 安装位置</h3>

    Copy the absolute path to the directory that you
    downloaded and extracted the Flutter SDK into.

    复制你下载并解压 Flutter SDK 所在目录的绝对路径。

 1. <h3>Add the Flutter SDK bin to your path</h3>

    <h3>将 Flutter SDK 的 bin 添加到你的 PATH</h3>

    To add the `bin` directory of your Flutter installation to your `PATH`:

    要将 Flutter 安装目录下的 `bin` 添加到 `PATH`：

    1. Copy the following command.

       复制以下命令。

    1. Replace `<path-to-sdk>` with the path to your Flutter SDK install.

       将 `<path-to-sdk>` 替换为你的 Flutter SDK 安装路径。

    1. Run the edited command in your preferred terminal.

       在你偏好的终端中运行编辑后的命令。

    ```console
    $ echo 'export PATH="<path-to-sdk>:$PATH"' >> ~/.bash_profile
    ```

    For example, if you downloaded Flutter into a
    `develop/flutter` folder inside your user directory,
    you'd run the following:

    例如，若你将 Flutter 下载到用户目录下的
    `develop/flutter` 文件夹，可运行：

    ```console
    $ echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.bash_profile
    ```

 1. <h3>Apply your changes</h3>

    <h3>应用你的更改</h3>

    To apply this change and get access to the `flutter` tool,
    close and reopen all open Zsh sessions in your terminal apps and IDEs.

    要应用此更改并访问 `flutter` 工具，
    请在终端应用和 IDE 中关闭并重新打开所有已打开的 Zsh 会话。

 1. <h3>Validate your setup</h3>

    <h3>验证你的配置</h3>

    To ensure you successfully added the SDK to your `PATH`,
    open a Zsh session in your preferred terminal,
    then try running the `flutter` and `dart` tools.

    为确保你已成功将 SDK 添加到 `PATH`，
    请在你偏好的终端中打开 Zsh 会话，
    然后尝试运行 `flutter` 和 `dart` 工具。

    ```console
    $ flutter --version
    $ dart --version
    ```

    If either command isn't found,
    check out [Flutter installation troubleshooting][troubleshoot].

    若任一命令未找到，
    请参阅 [Flutter 安装问题排查][troubleshoot]。

{: .steps}

[chromeos-linux]: https://support.google.com/chromebook/answer/9145439
[linux-path]: /install/add-to-path#linux
[troubleshoot]: /install/troubleshoot


