Dart: Dart Environment Setup & Toolchain
Last updated: 2026-08-26
The first step to writing good code is setting up a good environment.
1. What You Will Learn
- Installing the Dart SDK (Windows / macOS / Linux) and configuring the PATH
- Configuring VS Code with the Dart extension and debugger settings
- The four core commands:
dart run/dart compile/dart format/dart analyze - Introduction to
pubspec.yamlanddart createtemplates - Alice's first Hello World program
2. A Beginner's True Story
(1) Pain Point: Environment Setup Discourages Newcomers
Alice, a Python developer, just started learning Dart. She found 5 tutorials online, each recommending a different installation method — some using Homebrew, some Chocolatey, others manual download. After struggling for 2 hours, dart --version still reports "command not found". She almost gave up before writing a single line of code.
(2) The Right Solution
Installing the Dart SDK is actually just 3 steps: download → configure PATH → verify. With the VS Code Dart extension, you can go from installation to running your first program in just 10 minutes.
# Step 1: Verify installation
dart --version
# Step 2: Create first project
dart create hello_dart
# Step 3: Run it
cd hello_dart && dart run
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
(3) Benefits
- From zero to running in 10 minutes, no more getting stuck on environment setup
- VS Code provides syntax highlighting, intelligent code completion, and one-click debugging
dart analyzehelps you find potential issues as you write code
3. Dart SDK Installation
(1) Platform-Specific Installation Methods
flowchart TD A[Download SDK] --> B[Configure PATH] B --> C[VS Code + Extension] C --> D[dart create] D --> E[dart run] E --> F[Hello World]
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
| Platform | Recommended Method | Command |
|---|---|---|
| Windows | Chocolatey | choco install dart-sdk |
| macOS | Homebrew | brew install dart |
| Linux (Debian) | APT | See commands below |
| Linux (Generic) | Manual Download | Extract + Configure PATH |
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: Windows Installation
# Install via Chocolatey (run as Administrator)
choco install dart-sdk
# Verify installation
dart --version
# Expected output: Dart SDK version: 3.x.x
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: macOS Installation
# Install via Homebrew
brew tap dart-lang/dart
brew install dart
# Verify installation
dart --version
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: Linux (Debian/Ubuntu) Installation
# Add Dart APT repository
sudo apt-get update
sudo apt-get install apt-transport-https
sudo sh -c 'wget -qO- https://dl-ssl.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'
# Install Dart SDK
sudo apt-get update
sudo apt-get install dart
# Verify installation
dart --version
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
(2) PATH Configuration Verification
After installation, always verify the dart command is accessible:
# Check dart is in PATH
which dart # macOS/Linux
where dart # Windows
# If not found, add to PATH manually
# macOS/Linux: add to ~/.bashrc or ~/.zshrc
export PATH="$PATH:/usr/lib/dart/bin"
# Windows: add Dart SDK bin directory to System PATH
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
| Verification Item | Command | Expected Result |
|---|---|---|
| SDK Version | dart --version |
Dart SDK version: 3.x.x |
| Path Check | which dart |
/usr/lib/dart/bin/dart |
| pub Command | pub --version |
Pub 3.x.x |
4. VS Code Configuration
(1) Extension Installation
| Extension | Purpose | Required |
|---|---|---|
| Dart | Syntax highlighting, completion, debugging | Yes |
| Flutter (Optional) | Flutter development support | As needed |
| Dart Import (Optional) | Automatic import sorting | Recommended |
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: VS Code Debug Configuration
Create .vscode/launch.json in your project root:
{
"version": "0.2.0",
"configurations": [
{
"name": "Dart: Run",
"type": "dart",
"request": "launch",
"program": "bin/main.dart"
}
]
}
(2) Common VS Code Shortcuts
| Shortcut | Function |
|---|---|
| F5 | Start Debugging |
| Ctrl+F5 | Run Without Debugging |
| Ctrl+Shift+P → "Dart: Run" | Run from Command Palette |
| Ctrl+. | Quick Fix |
| Ctrl+Space | Intelligent Completion |
5. Four Core Commands
(1) dart run
Directly runs a Dart file or project using JIT mode, supporting hot reload.
# Run a single file
dart run bin/main.dart
# Run a project (using pubspec.yaml)
dart run
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
(2) dart compile
Compiles Dart code into different target artifacts.
| Subcommand | Artifact | Purpose |
|---|---|---|
dart compile exe |
Standalone executable | CLI tool distribution |
dart compile js |
JavaScript file | Web deployment |
dart compile aot-snapshot |
AOT snapshot | High-performance runtime |
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: Compile to Executable
# Compile to standalone executable
dart compile exe bin/main.dart -o datapipeline
# Run the executable
./datapipeline
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
(3) dart format
Automatically formats code, following the official Dart style guide.
# Format all Dart files in current directory
dart format .
# Format specific file
dart format lib/main.dart
# Check formatting without modifying files
dart format --set-exit-if-changed .
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
(4) dart analyze
Performs static analysis on code to find potential issues.
# Analyze current project
dart analyze
# Analyze with fatal infos
dart analyze --fatal-infos
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
| Command | Purpose | Development Stage |
|---|---|---|
dart run |
Run Code | Development |
dart compile |
Compile Artifacts | Release |
dart format |
Format Code | Before Commit |
dart analyze |
Static Analysis | Continuous |
6. pubspec.yaml and Project Templates
(1) Creating Projects with dart create
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: Create Project
# Create console application
dart create -t console-simple my_pipeline
# Project structure
# my_pipeline/
# ├── bin/
# │ └── my_pipeline.dart # Entry point
# ├── lib/
# │ └── my_pipeline.dart # Library code
# ├── test/
# │ └── my_pipeline_test.dart
# ├── pubspec.yaml # Dependencies
# └── analysis_options.yaml # Lint rules
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
(2) pubspec.yaml Structure Explained
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: pubspec.yaml Configuration
name: datapipeline
description: A CLI tool for e-commerce data analytics
version: 1.0.0
environment:
sdk: ^3.0.0
dependencies:
args: ^2.4.2
http: ^1.2.0
csv: ^6.0.0
dev_dependencies:
test: ^1.24.0
build_runner: ^2.4.0
| Field | Meaning | Example |
|---|---|---|
name |
Package name | datapipeline |
environment |
SDK version constraint | sdk: ^3.0.0 |
dependencies |
Runtime dependencies | http: ^1.2.0 |
dev_dependencies |
Development dependencies | test: ^1.24.0 |
7. Alice's First Hello World
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: Hello World
// Alice's first Dart program
void main() {
print('Hello, Dart!');
print('Welcome to DataPipeline project.');
}
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
Output:
Hello, Dart!
Welcome to DataPipeline project.
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: Hello World with Command Line Arguments
// Hello World with command line arguments
void main(List<String> arguments) {
final name = arguments.isNotEmpty ? arguments[0] : 'World';
print('Hello, $name!');
if (arguments.length > 1) {
print('Additional args: ${arguments.sublist(1)}');
}
}
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
Output (using
dart run bin/main.dart Alice --verbose):
Hello, Alice!
Additional args: [--verbose]
▶ Example
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
: Using the args Package for Argument Parsing
// Professional CLI argument parsing with args package
import 'package:args/args.dart';
void main(List<String> arguments) {
final parser = ArgParser()
..addOption('name', abbr: 'n', defaultsTo: 'World', help: 'Your name')
..addFlag('verbose', abbr: 'v', defaultsTo: false, help: 'Show verbose output');
final results = parser.parse(arguments);
final name = results['name'] as String;
final verbose = results['verbose'] as bool;
print('Hello, $name!');
if (verbose) {
print('Running in verbose mode');
}
}
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
8. Full Example: DataPipeline Project Initialization
// ============================================
// DataPipeline CLI - Initial Setup
// A professional CLI tool skeleton
// ============================================
import 'package:args/args.dart';
const String version = '1.0.0';
void main(List<String> arguments) {
final parser = ArgParser()
..addFlag('version', abbr: 'v', negatable: false, help: 'Show version')
..addFlag('help', abbr: 'h', negatable: false, help: 'Show help')
..addOption('input', abbr: 'i', help: 'Input data source path')
..addOption('output', abbr: 'o', defaultsTo: 'report.json', help: 'Output file path')
..addOption('format', allowed: ['json', 'csv', 'html'], defaultsTo: 'json', help: 'Output format')
..addFlag('verbose', help: 'Enable verbose logging');
try {
final results = parser.parse(arguments);
if (results['help'] as bool) {
print('DataPipeline - E-commerce analytics CLI tool');
print(parser.usage);
return;
}
if (results['version'] as bool) {
print('DataPipeline v$version');
return;
}
final input = results['input'] as String?;
final output = results['output'] as String;
final format = results['format'] as String;
final verbose = results['verbose'] as bool;
if (input == null) {
print('Error: --input is required');
print(parser.usage);
return;
}
print('=== DataPipeline v$version ===');
if (verbose) {
print('Input: $input');
print('Output: $output');
print('Format: $format');
}
print('Processing data from: $input');
print('Report saved to: $output ($format format)');
} on FormatException catch (e) {
print('Error: ${e.message}');
print(parser.usage);
}
}
> **Output:** Execute in local DartPad or with `dart run`. All Dart course examples are based on Dart 3.x / Flutter 3.x. Results may vary slightly with SDK versions.
Output (using
dart run bin/main.dart -i orders.csv -o report.json --verbose):
=== DataPipeline v1.0.0 ===
Input: orders.csv
Output: report.json
Format: json
Processing data from: orders.csv
Report saved to: report.json (json format)
❓ FAQ
Q: What to do if the
dartcommand is not found after installation? A: Check if your PATH environment variable includes the Dart SDK'sbindirectory. Usewhere darton Windows,which darton macOS/Linux to locate it.
Q: Do I need to install the Flutter SDK? A: If you are only learning the Dart language itself, no. Just install the standalone Dart SDK. You can install the Flutter SDK later when you start learning Flutter (it includes the Dart SDK).
Q: What's the difference between
dart runanddart compile exe? A:dart runuses JIT compilation for execution, ideal for development.dart compile execompiles into a standalone executable that can run without the SDK, ideal for distribution.
Q: Do I need to install both the Dart and Flutter extensions for VS Code? A: The Dart extension is mandatory. The Flutter extension is only needed for Flutter app development, not for pure Dart projects.
Q: What does the
^symbol mean in pubspec.yaml? A:^indicates compatibility within the major version. For example,^1.2.0means>=1.2.0 <2.0.0, allowing minor and patch upgrades.
Q:
dart analyzeshows many info-level warnings. Do I need to fix them all? A: Info-level messages are suggestions and don't affect execution. It's recommended to fix warnings and errors. Info messages depend on team conventions.
Q: How to choose a
dart createtemplate? A: Useconsole-simplefor CLI tools,package-simplefor libraries, andflutter-createfor Flutter. This tutorial usesconsole-simple.
📖 Summary
- The Dart SDK supports Windows, macOS, and Linux. Using a package manager is recommended.
- VS Code + Dart extension is the best development environment, offering integrated code completion, debugging, and formatting.
- Four core commands:
dart run(run),dart compile(compile),dart format(format),dart analyze(analyze). pubspec.yamlis the project's configuration center, managing dependencies and metadata.dart createcan quickly generate project templates, and theargspackage is used for CLI argument parsing.
📝 Exercises
- Basic (Difficulty ⭐): Install the Dart SDK, run
dart --versionto confirm the version is ≥ 3.0.0, then usedart create hello_dartto create and run your first project. - Intermediate (Difficulty ⭐⭐): Configure VS Code's
launch.jsonto run Dart programs with the F5 key, and try setting breakpoints for debugging. - Challenge (Difficulty ⭐⭐⭐): Write a CLI tool using the
argspackage that supports a--count Nparameter, outputting "Hello, DataPipeline!" N times, and compile it into an executable withdart compile exe.