【Using English】47 - MacOS install of Flutter


System requirements 系统要求

To install and run Flutter, your development environment must meet these minimum requirements:

  • Operating Systems: macOS (64-bit) 操作系统:macOS(64位)
  • Disk Space: 700 MB (does not include disk space for IDE/tools). 硬盘空间:700MB(不包括集成开发环境或工具的硬盘空间)
  • Tools: Flutter depends on these command-line tools being available in your environment. 工具: Flutter依赖于以下命令行工具在环境中可以运行。
    • bash
    • curl
    • git 2.x
    • mkdir
    • rm
    • unzip
    • which

Get the Flutter SDK

  1. Download the following installation bundle to get the latest stable release of the Flutter SDK:
    下载以下安装包来获取最新的稳定版Flutter SDK

    For other release channels, and older builds, see the SDK archive page.
    对于其他的发布渠道,或者之前的构建版本,请查看SDK 归档页面

  2. Extract the file in the desired location, for example:

 cd ~/development
 unzip ~/Downloads/flutter_macos_v1.7.8+hotfix.4-stable.zip
  1. Add the flutter tool to your path:
 export PATH="$PATH:`pwd`/flutter/bin"

This command sets your PATH variable for the current terminal window only. To permanently add Flutter to your path, see Update your path.


  1. Optionally, pre-download development binaries:
    The flutter tool downloads platform-specific development binaries as needed. For scenarios where pre-downloading these artifacts is preferable (for example, in hermetic build environments, or with intermittent network availability), iOS and Android binaries can be downloaded ahead of time by running:
 flutter precache

For additional download options, see flutter help precache.
想了解更多下载选项,请查看flutter 帮助预缓存

You are now ready to run Flutter commands!

Note: To update an existing version of Flutter, see Upgrading Flutter.


Run flutter doctor

Run the following command to see if there are any dependencies you need to install to complete the setup (for verbose output, add the -v flag):

 flutter doctor

This command checks your environment and displays a report to the terminal window. The Dart SDK is bundled with Flutter; it is not necessary to install Dart separately. Check the output carefully for other software you might need to install or further tasks to perform (shown in bold text).

这个命令检查您的环境,并且在终端窗口显示一个报告。Dart SDK已经与Flutter一起打包了,无需单独安装。仔细检查输出信息,因为您可以需要安装其他软件或执行进一步的任务。

For example:

[-] Android toolchain - develop for Android devices
    • Android SDK at /Users/obiwan/Library/Android/sdk
    ✗ Android SDK is missing command line tools; download from https://goo.gl/XxQghQ
    • Try re-installing or updating your Android SDK,
      visit https://flutter.dev/setup/#android-setup for detailed instructions.

The following sections describe how to perform these tasks and finish the setup process.


Once you have installed any missing dependencies, run the flutter doctor command again to verify that you’ve set everything up correctly.

每次你安装了缺少的依赖后,再次运行flutter doctor命令来验证是否已经设置正确了。

Warning: The flutter tool uses Google Analytics to anonymously report feature usage statistics and basic crash reports. This data is used to help improve Flutter tools over time. Analytics is not sent on the very first run or for any runs involving flutter config, so you can opt out of analytics before any data is sent. To disable reporting, type flutter config --no-analytics and to display the current setting, type flutter config. See Google’s Privacy Policy.

提示:flutter工具使用了Google分析来匿名报告特性使用情况的统计和基础的奔溃报告。随着时间的推移,该数据用来帮助提高Flutter工具。第一次运行或涉及到flutter配置的运行,分析数据不会被发送;所以您可以在分析被发送之前选择退出。想要关闭报告,可以输入flutter config --no-analytics;想要并显示当前的设置,输入flutter config.查看Google的隐私政策

Update your path

You can update your PATH variable for the current session only at the command line, as shown in Get the Flutter SDK. You’ll probably want to update this variable permanently, so you can run flutter commands in any terminal session.

正如在获取Flutter SDK中提到的一样,您可以仅在当前命令行更新PATH变量。您可能还想要永久地更新这个变量,这样您可以运行flutter命令在任何的终端。

The steps for modifying this variable permanently for all terminal sessions are machine-specific. Typically you add a line to a file that is executed whenever you open a new window. For example:


  1. Determine the directory where you placed the Flutter SDK. You will need this in Step 3.
    第一步:确定存放Flutter SDK的目录。第三步需要这个信息。
  2. Open (or create) $HOME/.bash_profile. The file path and filename might be different on your machine.
  3. Add the following line and change [PATH_TO_FLUTTER_GIT_DIRECTORY] to be the path where you cloned Flutter’s git repo:
  1. Run source $HOME/.bash_profile to refresh the current window.
    运行source $HOME/.bash_profile 来刷新当前的窗口
  2. Verify that the flutter/bin directory is now in your PATH by running:
 echo $PATH

For more details, see this StackExchange question.

Platform setup

MacOS supports developing Flutter apps for both iOS and Android. Complete at least one of the two platform setup steps now, to be able to build and run your first Flutter app.


iOS setup

Install Xcode

To develop Flutter apps for iOS, you need a Mac with Xcode 9.0 or newer:
想要开发iOS上的Flutter应用,您需要在Mac上安装Xcode9.0 或更高版本。

  1. Install Xcode 9.0 or newer (via web download or the Mac App Store).
  2. Configure the Xcode command-line tools to use the newly-installed version of Xcode by running the following from the command line:
 sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

This is the correct path for most cases, when you want to use the latest version of Xcode. If you need to use a different version, specify that path instead.

  1. Make sure the Xcode license agreement is signed by either opening Xcode once and confirming or runningsudo xcodebuild -license from the command line.

为了确保Xcode的许可协议已被签署,可以打开一次Xcode或者在命令行运行sudo xcodebuild -license

With Xcode, you’ll be able to run Flutter apps on an iOS device or on the simulator.


Set up the iOS simulator

To prepare to run and test your Flutter app on the iOS simulator, follow these steps:

  1. On your Mac, find the Simulator via Spotlight or by using the following command:
 open -a Simulator
  1. Make sure your simulator is using a 64-bit device (iPhone 5s or later) by checking the settings in the simulator’s Hardware > Device menu.
    通过在硬件 > 设备菜单里检查模拟器的设置,确保您的模拟器使用了64位的设备(iPhone 5s或者更新的设备)。
  2. Depending on your development machine’s screen size, simulated high-screen-density iOS devices might overflow your screen. Set the device scale under the Window > Scale menu in the simulator.
    依赖于开发设备的屏幕尺寸,模拟高清分辨率的iOS设备也许会超出您的屏幕。在窗口 > 缩放菜单中设置设备缩放度来调整模拟器。

Create and run a simple Flutter app

To create your first Flutter app and test your setup, follow these steps:

  1. Create a new Flutter app by running the following from the command line:
    运行以下命令 创建一个新的Flutter应用。
 flutter create my_app
  1. A my_app directory is created, containing Flutter’s starter app. Enter this directory:
 cd my_app
  1. To launch the app in the Simulator, ensure that the Simulator is running and enter:
    想要在模拟器中启动应用,确保模拟器正在运行并输入flutter run
 flutter run

Deploy to iOS devices

To deploy your Flutter app to a physical iOS device, you’ll need some additional tools and an Apple account. You’ll also need to set up physical device deployment in Xcode.

  1. Install homebrew.
  2. Ensure that homebrew is up to date:
 brew update
  1. Install the tools for deploying Flutter apps to iOS devices by running the following commands:
 brew install --HEAD usbmuxd
 brew link usbmuxd
 brew install --HEAD libimobiledevice
 brew install ideviceinstaller ios-deploy cocoapods
 pod setup

Note: The first two commands above are necessary as a temporary workaround until the next release of libusbmuxd, as explained in libusbmuxd issue #46 and Flutter issue #22595.


If any of these commands fail, run brew doctor and follow the instructions to resolve any issues.

如果这些命令汇总的任何一个运行失败了,运行brew doctor并且遵循说明来解决对应的问题。

  1. Follow the Xcode signing flow to provision your project:

    1. Open the default Xcode workspace in your project by running open ios/Runner.xcworkspace in a terminal window from your Flutter project directory.
      在工程中,通过在终端窗口中运行open ios/Runner.xcworkspace打开Xcode默认的工作空间

    2. In Xcode, select the Runner project in the left navigation panel.

    3. In the Runner target settings page, make sure your Development Team is selected under General > Signing > Team. When you select a team, Xcode creates and downloads a Development Certificate, registers your device with your account, and creates and downloads a provisioning profile (if needed).
      Runner目标设置页面,确保您已经在通用 > 签名 > 团队中选择了您的开发团队。当您选择了团队,Xcode会创建并且下载一个开发证书,用您的账号注册您的设备,如果需要的话,也会创建并下载一个提供好的档案。

      • To start your first iOS development project, you might need to sign into Xcode with your Apple ID.

        Xcode account add

      Development and testing is supported for any Apple ID. Enrolling in the Apple Developer Program is required to distribute your app to the App Store. For details about membership types, see Choosing a Membership.
      任何AppleID都支持开发和测试。想要发布您的应用到App Store,您需要注册苹果开发者。关于会员类型的更多细节,请查看选择一种会员

      • The first time you use an attached physical device for iOS development, you will need to trust both your Mac and the Development Certificate on that device. Select Trust in the dialog prompt when first connecting the iOS device to your Mac.

        Trust Mac

        Then, go to the Settings app on the iOS device, select General > Device Management and trust your Certificate.
        然后,在iOS设备的设置应用中,选择通用 > 设备管理并信任您的证书。

      • If automatic signing fails in Xcode, verify that the project’s General > Identity > Bundle Identifiervalue is unique.
        如果Xcode中的自动签名失败了,验证工程的通用 > 身份 > 包标识符的值是否唯一

        Check the app's Bundle ID

  2. Start your app by running flutter run.
    运行应用通过运行flutter run

Android setup

Note: Flutter relies on a full installation of Android Studio to supply its Android platform dependencies. However, you can write your Flutter apps in a number of editors; a later step will discuss that.

提示: Flutter依赖一个Android Studio的全量安装,来支持Flutter Android平台的依赖。但是,你可以在很多编辑器中写Flutter应用(安装了但可以不用。。。),之后的步骤中将会讨论。

Install Android Studio

  1. Download and install Android Studio.
    下载并安装Android Studio
  2. Start Android Studio, and go through the ‘Android Studio Setup Wizard’. This installs the latest Android SDK, Android SDK Platform-Tools, and Android SDK Build-Tools, which are required by Flutter when developing for Android.
    开启Android Studio,并完成安装向导。这样,已经安装了最新的Android SDK,Android SDK 平台工具,和 Android SDK打包工具,这些都是使用Flutter开发Android时需要的。

Set up your Android device

To prepare to run and test your Flutter app on an Android device, you’ll need an Android device running Android 4.1 (API level 16) or higher.
想要准备在一个Android设备上运行和测试您的Flutter应用,您需要一个运行着Android4.1(API 等级16)及以上的Android设备。

  1. Enable Developer options and USB debugging on your device. Detailed instructions are available in theAndroid documentation.
  2. Windows-only: Install the Google USB Driver.
    只针对Windows设备,安装Google USB 驱动
  3. Using a USB cable, plug your phone into your computer. If prompted on your device, authorize your computer to access your device.
  4. In the terminal, run the flutter devices command to verify that Flutter recognizes your connected Android device. By default, Flutter uses the version of the Android SDK where your adb tool is based. If you want Flutter to use a different installation of the Android SDK, you must set the ANDROID_HOME environment variable to that installation directory.
    在终端里,运行命令flutter devices来检验Flutter已经检测到您连接好的设备。默认地,Flutter使用adb工具依赖的Android SDK版本。如果您想要Flutter使用一个不同的AndroidSDK安装,您必须设置ANDROID_HOME环境变量在那个对应的安装目录。

Set up the Android emulator

To prepare to run and test your Flutter app on the Android emulator, follow these steps:

  1. Enable VM acceleration on your machine.
  2. Launch Android Studio > Tools > Android > AVD Manager and select Create Virtual Device. (The Androidsubmenu is only present when inside an Android project.)
    打开Android Studio > 工具 > Android > AVD 管理器并选择创建虚拟设备(Android子目录只有在Android工程中才会看到)
  3. Choose a device definition and select Next.
  4. Select one or more system images for the Android versions you want to emulate, and select Next. An x86or x86_64 image is recommended.
  5. Under Emulated Performance, select Hardware - GLES 2.0 to enable hardware acceleration.
  6. Verify the AVD configuration is correct, and select Finish.
    For details on the above steps, see Managing AVDs.
  7. In Android Virtual Device Manager, click Run in the toolbar. The emulator starts up and displays the default canvas for your selected OS version and device.