將 Flutter 加入 PATH
了解如何在下載 SDK 後,將 Flutter 加入你的 PATH 環境變數。 將 Flutter 加入你的 PATH,即可在終端機與 IDE 中使用 flutter 和 dart 命令列工具。
在 Windows 上將 Flutter 加入你的 path。
在 macOS 上將 Flutter 加入你的 path。
在 Linux 上將 Flutter 加入你的 path。
在 ChromeOS 上將 Flutter 加入你的 path。
Windows
#若要在 Windows 的終端機中執行 flutter 和 dart 指令, 請將 Flutter SDK 的 bin 目錄加入 Path 環境變數。
Determine your Flutter SDK installation location
Copy the absolute path to the directory that you downloaded and extracted the Flutter SDK into.
Navigate to the environment variables settings
Press Windows + Pause.
If your keyboard lacks a Pause key, try Windows + Fn + B.
The System > About dialog opens.
Click Advanced System Settings > Advanced > Environment Variables....
The Environment Variables dialog opens.
Add the Flutter SDK bin to your path
In the User variables for (username) section of the Environment Variables dialog, look for the Path entry.
If the Path entry exists, double-click it.
The Edit Environment Variable dialog should open.
Double-click inside an empty row.
Type the path to the
bindirectory of your Flutter installation.For example, if you downloaded Flutter into a
develop\flutterfolder inside your user directory, you'd type the following:%USERPROFILE%\develop\flutter\binClick the Flutter entry you added to select it.
Click Move Up until the Flutter entry sits at the top of the list.
To confirm your changes, click OK three times.
If the entry doesn't exist, click New....
The Edit Environment Variable dialog should open.
In the Variable Name box, type
Path.In the Variable Value box, type the path to the
bindirectory of your Flutter installation.For example, if you downloaded Flutter into a
develop\flutterfolder inside your user directory, you'd type the following:%USERPROFILE%\develop\flutter\binTo confirm your changes, click OK three times.
Apply your changes
To apply this change and get access to the
fluttertool, close and reopen all open command prompts, sessions in your terminal apps, and IDEs.Validate your setup
To ensure you successfully added the SDK to your
PATH, open command prompt or your preferred terminal app, then try running theflutteranddarttools.flutter --version dart --versionIf either command isn't found, check out Flutter installation troubleshooting.
macOS
#若要在 macOS 的終端機中執行 flutter 和 dart 指令, 請將 Flutter SDK 的 bin 目錄加入 PATH 環境變數。
Determine your Flutter SDK installation location
Copy the absolute path to the directory that you downloaded and extracted the Flutter SDK into.
Open or create the Zsh environment variable file
If it exists, open the Zsh environment variable file
~/.zprofilein your preferred text editor. If it doesn't exist, create the~/.zprofilefile.Add the Flutter SDK bin to your path
At the end of your
~/.zprofilefile, use the built-inexportcommand to update thePATHvariable to include thebindirectory of your Flutter installation.Replace
<path-to-sdk>with the path to your Flutter SDK installation.bashexport PATH="<path-to-sdk>/bin:$PATH"For example, if you downloaded Flutter into a
develop/flutterfolder inside your user directory, you'd add the following to the file:bashexport PATH="$HOME/develop/flutter/bin:$PATH"Save your changes
Save, then close, the
~/.zprofilefile you edited.Apply your changes
To apply this change and get access to the
fluttertool, close and reopen all open Zsh sessions in your terminal apps and IDEs.Validate your setup
To ensure you successfully added the SDK to your
PATH, open a Zsh session in your preferred terminal, then try running theflutteranddarttools.flutter --version dart --versionIf either command isn't found, check out Flutter installation troubleshooting.
Linux
#若要在 Linux 的終端機中執行 flutter 和 dart 指令, 請將 Flutter SDK 的 bin 目錄加入 PATH 環境變數。
Determine your Flutter SDK installation location
Copy the absolute path to the directory that you downloaded and extracted the Flutter SDK into.
Determine your default shell
If you don't know what shell you use, check which shell starts when you open a new console window.
echo $SHELLAdd the Flutter SDK bin to your path
To add the
bindirectory of your Flutter installation to yourPATH:- Expand the instructions for your default shell.
- Copy the provided command.
- Replace
<path-to-sdk>with the path to your Flutter SDK install. - Run the edited command in your preferred terminal with that shell.
Expand for
bashinstructionsecho 'export PATH="<path-to-sdk>:$PATH"' >> ~/.bash_profileFor example, if you downloaded Flutter into a
develop/flutterfolder inside your user directory, you'd run the following:echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.bash_profileExpand for
zshinstructionsecho 'export PATH="<path-to-sdk>/bin:$PATH"' >> ~/.zshenvFor example, if you downloaded Flutter into a
develop/flutterfolder inside your user directory, you'd run the following:echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.zshenvExpand for
fishinstructionsfish_add_path -g -p <path-to-sdk>/binFor example, if you downloaded Flutter into a
develop/flutterfolder inside your user directory, you'd run the following:fish_add_path -g -p ~/develop/flutter/binExpand for
cshinstructionsecho 'setenv PATH "<path-to-sdk>/bin:$PATH"' >> ~/.cshrcFor example, if you downloaded Flutter into a
develop/flutterfolder inside your user directory, you'd run the following:echo 'setenv PATH "$HOME/develop/flutter/bin:$PATH"' >> ~/.cshrcExpand for
tcshinstructionsecho 'setenv PATH "<path-to-sdk>/bin:$PATH"' >> ~/.tcshrcFor example, if you downloaded Flutter into a
develop/flutterfolder inside your user directory, you'd run the following:echo 'setenv PATH "$HOME/develop/flutter/bin:$PATH"' >> ~/.tcshrcExpand for
kshinstructionsecho 'export PATH="<path-to-sdk>/bin:$PATH"' >> ~/.profileFor example, if you downloaded Flutter into a
develop/flutterfolder inside your user directory, you'd run the following:echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.profileExpand for
shinstructionsecho 'export PATH="<path-to-sdk>/bin:$PATH"' >> ~/.profileFor example, if you downloaded Flutter into a
develop/flutterfolder inside your user directory, you'd run the following:echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.profileApply your changes
To apply this change and get access to the
fluttertool, close and reopen all open shell sessions in your terminal apps and IDEs.Validate your setup
To ensure you successfully added the SDK to your
PATH, open your preferred terminal with your default shell, then try running theflutteranddarttools.flutter --version dart --versionIf either command isn't found, check out Flutter installation troubleshooting.
ChromeOS
#若要在 ChromeOS 的終端機中執行 flutter 和 dart 指令, 請將 Flutter SDK 的 bin 目錄加入 PATH 環境變數。
Determine your Flutter SDK installation location
Copy the absolute path to the directory that you downloaded and extracted the Flutter SDK into.
Add the Flutter SDK bin to your path
To add the
bindirectory of your Flutter installation to yourPATH:- Copy the following command.
- Replace
<path-to-sdk>with the path to your Flutter SDK install. - Run the edited command in your preferred terminal.
echo 'export PATH="<path-to-sdk>:$PATH"' >> ~/.bash_profileFor example, if you downloaded Flutter into a
develop/flutterfolder inside your user directory, you'd run the following:echo 'export PATH="$HOME/develop/flutter/bin:$PATH"' >> ~/.bash_profileApply your changes
To apply this change and get access to the
fluttertool, close and reopen all open Zsh sessions in your terminal apps and IDEs.Validate your setup
To ensure you successfully added the SDK to your
PATH, open a Zsh session in your preferred terminal, then try running theflutteranddarttools.flutter --version dart --versionIf either command isn't found, check out Flutter installation troubleshooting.