如何安装Dart v2?遍查官方文档无果求助
Hey there! I totally get how frustrating it is to dig through the Dart docs looking for installation steps when they seem to gloss over the obvious stuff. Let me walk you through exactly how to get Dart v2 (either stable or dev channel) set up—since you need it for those AngularDart components.
First, quick recap on the channels to make sure we're on the same page:
- Stable channel: The most reliable, thoroughly tested version—perfect for production or consistent development work
- Dev channel: Cutting-edge features, but might have occasional bugs—great if you need the latest tools for testing
Step 1: Pick Your Installation Method
Option 1: Manual SDK Download (Works for All Platforms)
This is straightforward and gives you full control:
- Navigate to the Dart SDK download section (it’s usually under the "Get Dart" menu on the official site—easy to miss at first!)
- Select either Stable or Dev from the channel dropdown
- Download the package matching your OS:
- Windows:
.zipfile - macOS/Linux:
.tar.gzfile
- Windows:
- Extract the downloaded file to a permanent location on your computer (e.g.,
C:\dart-sdkfor Windows,/usr/local/dart-sdkfor macOS/Linux) - Add the
binfolder inside the extracted SDK directory to your system’s PATH:- Windows: Open System Properties → Advanced → Environment Variables, find the
Pathvariable, and add the full path todart-sdk\bin(likeC:\dart-sdk\bin) - macOS/Linux: Open your terminal config file (
~/.bashrc,~/.zshrc, or~/.profile), addexport PATH="$PATH:/usr/local/dart-sdk/bin", then runsource ~/.zshrc(or your respective file) to apply the change right away
- Windows: Open System Properties → Advanced → Environment Variables, find the
Option 2: Package Managers (Simpler for Updates)
If you prefer automated installs and easy updates, use these platform-specific tools:
- macOS (Homebrew):
- Stable channel: Run
brew install dartin your terminal - Dev channel: Run
brew install dart --head
- Stable channel: Run
- Windows (Chocolatey):
- Open Command Prompt as administrator
- Stable channel:
choco install dart-sdk - Dev channel:
choco install dart-sdk --pre
- Linux (Debian/Ubuntu):
- First, run
sudo apt-get update && sudo apt-get install apt-transport-httpsto enable secure repo access - Add the Dart repo: For stable, run
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/dart.gpg] https://dl.dartlang.org/linux/debian stable main" > /etc/apt/sources.list.d/dart_stable.list'- For dev channel, replace
stablewithdevin the line above
- For dev channel, replace
- Install the SDK:
sudo apt-get update && sudo apt-get install dart
- First, run
Step 3: Verify Your Installation
Open a brand new terminal or Command Prompt window (old windows might not pick up PATH changes) and run:
dart --version
You should see a version number starting with 2.x.x or higher—exactly what you need for AngularDart components.
Quick Tip: Switching Channels Later
If you ever want to switch between stable and dev versions:
- Manual install: Just download the SDK for your desired channel, replace your existing SDK directory, and double-check your PATH is pointing to the new folder
- Package manager: Use the update command for the target channel (e.g.,
brew upgrade dart --headfor dev on macOS,choco upgrade dart-sdk --prefor Windows)
A quick heads-up: AngularDart components do require Dart v2 or later, so if you run into build errors after installing, double-check your PATH—sometimes old SDK versions can linger and cause conflicts.
内容的提问来源于stack exchange,提问作者Dean Chalk

