目录

Contents

获取 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.

安装 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.

Note: The Flutter SDK includes the full Dart SDK, and has Dart’s dart command-line interface in its bin folder.

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
$ wget -qO- https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
$ echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /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.

$ echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.flutter-io.cn/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.

然后安装 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

安装 Homebrew 后运行以下命令:

Install Homebrew, and then run the following commands:

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

想要更新到 Dart SDK 可用的更新版本,执行以下命令:

To upgrade when a new release of Dart is available:

$ brew upgrade dart

想要切换本地 Dart SDK 的版本,在你没有安装之前,需要先行安装对应版本。例如,以下的命令将安装 Dart 2.12:

To switch between locally installed Dart releases, first install the version you want to switch to if you haven’t. For example, to install Dart 2.12:

$ brew install dart@2.12

接着切换版本时,取消当前版本的链接,并链接目标版本。

Then to switch between versions, unlink the current version and link the desired version.

$ brew unlink dart@<old> && brew unlink dart@<new> && brew link dart@<new>

运行以下命令查看已经安装的 Dart 版本:

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、ARM64、ARM、RISC-V (RV64GC)。
    RISC-V 的支持目前还在实验阶段,仅在 beta 和 dev 渠道可用。

    Supported architectures: x64, IA32, ARM64, ARM, RISC-V (RV64GC).
    Support for RISC-V is experimental, and is available only in the beta and dev channels.

macOS

  • Supported versions: Latest three major versions. As of November 2021, the following versions are supported:
    • macOS 10.15 (Catalina)
    • macOS 11 (Big Sur)
    • 支持的版本:最新的三个主要版本。截止 2021 年 11 月,支持以下版本:

      macOS 12 (Monterey)

    • macOS 10.15 (Catalina)
    • macOS 11 (Big Sur)
    • macOS 12 (Monterey)
  • 支持的架构: 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.