目录

Contents

获取 Dart SDK

本页面指引你如何下载 Dart SDK。 Dart SDK 包含开发 Web、命令行和服务端应用所需要的库和命令行工具。更多详细内容,请参考 Dart SDK 概览 文档。

This page describes how to download the Dart SDK. The Dart SDK has the libraries and command-line tools that you need to develop Dart command-line, server, and non-Flutter web apps. For details, see the Dart SDK overview.

从 Flutter 1.21 版本开始,Flutter SDK 会同时包含完整的 Dart SDK 因此如果你已经安装了 Flutter,可能就无需再特别下载 Dart SDK 了。如果你有下述的需求,请考虑下载 Dart SDK:

As of Flutter 1.21, the Flutter SDK includes the full Dart SDK. So if you have Flutter installed, you might not need to explicitly download the Dart SDK. Consider downloading the Dart SDK if any of the following are true:

  • 不需要使用 Flutter;

    You don’t use Flutter.

  • 使用 Flutter 1.21 之前的版本;

    You use a pre-1.21 version of Flutter.

  • 希望降低电脑存储空间的使用,此次用例并不需要 Flutter,比如:设置 CI 时,需要 Dart 并不需要 Flutter。

    You want to reduce disk space requirements or download time, and your use case doesn’t require Flutter. For example, you might have a continuous integration (CI) setup that requires Dart but not Flutter.

安装 Dart SDK

Installing the Dart SDK

如下所述,你可以使用包管理轻松地安装和更新 Dart SDK。你也可以以 编译 SDK 源码 的形式安装,也可以在我们的 各个发布渠道里 下载 SDK 的 zip 压缩文件

As the following instructions show, you can use a package manager to easily install and update a stable channel Dart SDK. Alternatively, you can build the SDK from source, grab a Dart Docker image, or install from any release channel by downloading the SDK as a zip file.

You can install the Dart SDK using Chocolatey.

安装 Dart SDK:

To install the Dart SDK:

C:\> choco install dart-sdk

升级 Dart SDK:

To upgrade the Dart SDK:

C:\> choco upgrade dart-sdk

SDK 默认会安装在 C:\tools\dart-sdk。你可以更改 ChocolateyToolsLocation 环境变量来选择安装目录。

By default, the SDK is installed at C:\tools\dart-sdk. You can change that location by setting the ChocolateyToolsLocation environment variable to your chosen installation directory.

如果安装后你无法使用 Dart SDK 的可执行文件,请将 SDK 的路径添加到 PATH:

If you can’t use the Dart SDK executables, add the SDK location to your PATH:

  1. 打开 Windows 搜索,输入 env

    In the Windows search box, type env.

  2. 点击 编辑系统环境变量

    Click Edit the system environment variables.

  3. 点击 环境变量(N)…

    Click Environment Variables….

  4. 在用户变量部分,选择 Path 并点击 编辑(E)…

    In the user variable section, select Path and click Edit….

  5. 点击 新建(N),输入 dart-sdk 的路径。

    Click New, and enter the path to the dart-sdk directory.

  6. 在每个打开的窗口点击 应用(A)确定,关闭弹窗并应用路径修改。

    In each window that you just opened, click Apply or OK to dismiss it and apply the path change.

如果您使用 64 位的 Debian/Ubuntu 系统,请选择下面任意一种方式安装,在新版本发布之后,它们都可以自动更新。

If you’re using Debian/Ubuntu on AMD64 (64-bit Intel), you can choose one of the following options, both of which can update the SDK automatically when new versions are released.

使用 apt-get 方式安装

Install using apt-get

请使用如下的方式(只需设置一次):

Perform the following one-time setup:

$ sudo apt-get update
$ sudo apt-get install apt-transport-https
$ sudo sh -c 'wget -qO- https://dl.google.com/linux/linux_signing_key.pub | apt-key add -'
$ sudo sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'

中国的开发者,请将上面最后一行命令行的 storage.googleapis.com 替换为 storage.flutter-io.cn,如下:

Developers from China: please considering replace to the mirror site that you trusted.

$ sudo sh -c 'wget -qO- https://storage.flutter-io.cn/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'

我们尚未完整测试和保证这个镜像的稳定性,不过有任何问题,您都可以点击文档右上方进行反馈。

Note: we didn’t fully tested this mirror, it could be unstable, if you have any questions, please file an issue to us.

然后安装 Dart SDK:

Then install the Dart SDK:

$ sudo apt-get update
$ sudo apt-get install dart

使用 Debian 安装包

Install a Debian package

通过 .deb 软件包 下载 Dart SDK。

Alternatively, download Dart SDK as a Debian package in the .deb package format.

在 PATH 环境变量里加入所有 Dart 二进制文件的访问

Modify PATH for access to all Dart binaries

安装 SDK 之后需要把 SDK 的 bin 目录加入你环境变量的 PATH 中去。比如,通过下面的命令可以在现有命令行窗口中加入 PATH 环境变量:

After installing the SDK, add its bin directory to your PATH. For example, use the following command to change PATH in your active terminal session:

$ export PATH="$PATH:/usr/lib/dart/bin"

为未来的命令行窗口执行永久的 PATH 环境变量设定,可以使用下面的命令:

To change the PATH for future terminal sessions, use a command like this:

$ echo 'export PATH="$PATH:/usr/lib/dart/bin"' >> ~/.profile

Install Homebrew, and then run the following commands:

$ brew tap dart-lang/dart
$ brew install dart

To upgrade when a new release of Dart is available:

$ brew upgrade dart

To switch between locally installed Dart releases, use brew switch dart <version>. Example:

$ brew switch dart 2.12.4

To see which versions of Dart you’ve installed:

$ brew info dart

系统要求

System requirements

Dart SDK 支持 Windows、Linux 和 macOS。

The Dart SDK is supported on Windows, Linux, and macOS.

Windows

  • 支持的版本:Windows 10。

    Supported versions: Windows 10.

  • 支持的架构:x64、ia32。

    Supported architectures: x64, ia32.

Linux

  • 支持的版本:已支持标准版的 Debian stable 以及 Ubuntu LTS

    Supported versions: Debian stable and Ubuntu LTS under standard support.

  • 支持的架构:x64、ia32、arm、arm64。

    Supported architectures: x64, ia32, arm, arm64.

macOS

  • Supported versions: Latest three major versions. As of April 2021, the following versions are supported:
    • macOS 10.14 (Mojave)
    • macOS 10.15 (Catalina)
    • macOS 11 (Big Sur)

    支持的版本:最新的三个主要版本。截止 2021 年 4 月,支持以下版本:

    • macOS 10.14 (Mojave)
    • macOS 10.15 (Catalina)
    • macOS 11 (Big Sur)
  • 支持的架构:x64、arm64。

    Supported architectures: x64, arm64.

关于发行渠道和版本字符串

About release channels and version strings

Dart SDK 有三个发布渠道:

The Dart SDK has three release channels:

  • 稳定版 (Stable)渠道:稳定发行版,每 三个月 更新一次;当前版本 [calculating].

    Stable channel: stable releases, updated roughly every three months; currently [calculating].

    稳定版可适用于生产环节。

    Stable releases are suitable for production use.

  • 测试版 (Beta) 渠道:也称 发行预览版,通常 每月 更新一次;当前版本 [calculating].

    Beta channel: preview releases, usually updated every month; currently [calculating].

    测试版渠道的构建是稳定版渠道的“预览版构建”。我们推荐您使用这个渠道的 SDK、进行测试,但是不建议您的应用发布,您可以用这个渠道的构建预览新功能或测试与未来版本的兼容性。

    Beta channel builds are preview builds for the stable channel. We recommend testing, but not releasing, your apps against beta to preview new features or test compatibility with future releases.

  • 开发版 (Dev)渠道:也称 预发行版,通常每 双周 更新一次;当前版本 [calculating].

    Dev channel: prereleases, usually updated twice a week; currently [calculating].

    开发版渠道的构建包含最新的更新,也可能本身就是不完善的,这个版本我们不受支持,并且可能会包含未经审核的重大更改 (breaking changes)。

    Dev channel releases are the most current with latest changes, may be broken, are unsupported, and may contain unvetted breaking changes.

Dart SDK 稳定版 构建渠道的版本号设定为 x.y.z,比如 1.24.32.1.0。它们由点分隔的整数组成,没有连字符或字母,其中 x 是主版本,y 是次要版本,而 z 是补丁版本。

Stable channel releases of the Dart SDK have x.y.z version strings like 1.24.3 and 2.1.0. They consist of dot-separated integers, with no hyphens or letters, where x is the major version, y is the minor version, and z is the patch version.

Dart SDK 的非稳定版 (测试版 (Beta)开发版 (Dev)) 构建渠道的版本号设定为:x.y.z-a.b.<beta|dev>,比如:2.8.0-20.11.beta。连字符前的部分 (x.y.z) 遵循稳定版本方案,连字符后的 ab 分别是预发行版和预发行补丁版本,而 betadev 是构建渠道通道标示。

Beta and dev channel releases of the Dart SDK (non-stable releases) have x.y.z-a.b.<beta|dev> versions like 2.8.0-20.11.beta. The part before the hyphen follows the stable version scheme, a and b after the hyphen are the prerelease and prerelease patch versions, and beta or dev is the channel.

你可以通过 instructions above 获得 stable 和 dev 渠道,或者你也可以直接下载 SDK 的压缩包

You can get stable channel releases using the instructions above, or you can get stable, beta, or dev channel releases using a package manager or Dart Docker image, or by downloading the SDK as a zip file.

你可以查阅 Dart 2 相关页面 获取更多信息。

For more information, see the Dart 2 page.