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


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.

BASH
# Step 1: Verify installation
dart --version

# Step 2: Create first project
dart create hello_dart

# Step 3: Run it
cd hello_dart && dart run
TEXT 📖 Display only
> **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


3. Dart SDK Installation

(1) Platform-Specific Installation Methods

100%
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]
TEXT 📖 Display only
> **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

TEXT 📖 Display only
> **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

BASH
# Install via Chocolatey (run as Administrator)
choco install dart-sdk

# Verify installation
dart --version
# Expected output: Dart SDK version: 3.x.x
TEXT 📖 Display only
> **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

TEXT 📖 Display only
> **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

BASH
# Install via Homebrew
brew tap dart-lang/dart
brew install dart

# Verify installation
dart --version
TEXT 📖 Display only
> **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

TEXT 📖 Display only
> **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

BASH
# 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
TEXT 📖 Display only
> **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:

BASH
# 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
TEXT 📖 Display only
> **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

TEXT 📖 Display only
> **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:

JSON
{
  "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.

BASH
# Run a single file
dart run bin/main.dart

# Run a project (using pubspec.yaml)
dart run
TEXT 📖 Display only
> **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

TEXT 📖 Display only
> **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

BASH
# Compile to standalone executable
dart compile exe bin/main.dart -o datapipeline

# Run the executable
./datapipeline
TEXT 📖 Display only
> **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.

BASH
# 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 .
TEXT 📖 Display only
> **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.

BASH
# Analyze current project
dart analyze

# Analyze with fatal infos
dart analyze --fatal-infos
TEXT 📖 Display only
> **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

TEXT 📖 Display only
> **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

BASH
# 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
TEXT 📖 Display only
> **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

TEXT 📖 Display only
> **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

YAML
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

TEXT 📖 Display only
> **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

DART
// Alice's first Dart program
void main() {
  print('Hello, Dart!');
  print('Welcome to DataPipeline project.');
}
TEXT 📖 Display only
> **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:

TEXT 📖 Display only
Hello, Dart!
Welcome to DataPipeline project.

▶ Example

TEXT 📖 Display only
> **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

DART
// 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)}');
  }
}
TEXT 📖 Display only
> **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):

TEXT 📖 Display only
Hello, Alice!
Additional args: [--verbose]

▶ Example

TEXT 📖 Display only
> **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

DART
// 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');
  }
}
TEXT 📖 Display only
> **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

DART
// ============================================
// 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);
  }
}
TEXT 📖 Display only
> **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):

TEXT 📖 Display only
=== 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 dart command is not found after installation? A: Check if your PATH environment variable includes the Dart SDK's bin directory. Use where dart on Windows, which dart on 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 run and dart compile exe? A: dart run uses JIT compilation for execution, ideal for development. dart compile exe compiles 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.0 means >=1.2.0 <2.0.0, allowing minor and patch upgrades.

Q: dart analyze shows 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 create template? A: Use console-simple for CLI tools, package-simple for libraries, and flutter-create for Flutter. This tutorial uses console-simple.


📖 Summary


📝 Exercises

  1. Basic (Difficulty ⭐): Install the Dart SDK, run dart --version to confirm the version is ≥ 3.0.0, then use dart create hello_dart to create and run your first project.
  2. Intermediate (Difficulty ⭐⭐): Configure VS Code's launch.json to run Dart programs with the F5 key, and try setting breakpoints for debugging.
  3. Challenge (Difficulty ⭐⭐⭐): Write a CLI tool using the args package that supports a --count N parameter, outputting "Hello, DataPipeline!" N times, and compile it into an executable with dart compile exe.

← Previous Lesson | Next Lesson →

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏