Skip to main content
The dart command-line tool is the primary interface for Dart development. It provides a unified entry point for running Dart programs, managing packages, analyzing code, and more.

Overview

The dart tool consolidates various development tasks into a single command-line interface:
dart <command|dart-file> [arguments]

Global Options

These options apply to all dart commands:
dart -v <command>
dart --verbose <command>

Analytics Options

# Enable analytics
dart --enable-analytics

# Disable analytics
dart --disable-analytics

# Suppress analytics for a single run
dart --suppress-analytics <command>

Available Commands

analyze

Analyze Dart code in a directory.
dart analyze [<directory>]
See the Analyzer documentation for more details.

compile

Compile Dart to various formats.
dart compile <subcommand> [arguments]
Subcommands:
  • js - Compile to JavaScript
  • jit-snapshot - Compile to JIT snapshot
  • kernel - Compile to kernel snapshot
  • exe - Compile to native executable
  • aot-snapshot - Compile to AOT snapshot
  • wasm - Compile to WebAssembly
dart compile exe bin/main.dart -o build/app

create

Create a new Dart project.
dart create [options] <directory>
dart create my_app
Available templates:
  • console - A command-line application (default)
  • package - A package containing shared Dart libraries
  • web - A web application
  • server-shelf - A server app using package:shelf

devtools

Open Dart DevTools for debugging and profiling.
dart devtools [options] [service-protocol-uri]
See the DevTools documentation for more details.

doc

Generate API documentation for Dart projects.
dart doc [options] [<input directory>]
# Generate documentation for the current package
dart doc

# Generate docs with a custom output directory
dart doc --output=docs/api

# Validate documentation without generating
dart doc --validate-links

fix

Apply automated fixes to Dart source code.
dart fix [options] [<directory>]
# Show what fixes would be applied
dart fix --dry-run

format

Format Dart source code.
dart format [options] <files or directories>
See the Formatter documentation for more details.

info

Show diagnostic information about the installed tooling.
dart info
Example output:
$ dart info

General info:
  Dart 3.5.0 (stable) (Mon Jul 8 13:45:56 2024 +0000) on "macos_arm64"
  on macos / arm64
  locale is en-US

Process info:
  memory: 15.2 MB
  started at: 2024-07-08 10:30:15

pub

Work with packages using the Pub package manager.
dart pub <subcommand> [arguments]
See the Pub documentation for more details.

run

Run a Dart program.
dart run [vm-options] <dart-file>|<package>[:executable] [args]
# Run a Dart script file
dart run bin/main.dart

# With arguments
dart run bin/main.dart --verbose --port=8080

VM Options

You can pass VM options before the script name:
# Enable asserts
dart run --enable-asserts bin/main.dart

# Set observatory port
dart run --observe=8181 bin/main.dart

# Enable experiments
dart run --enable-experiment=macros bin/main.dart

test

Run tests for a project.
dart test [options] [files or directories]
# Run all tests
dart test

Running Dart Programs

You can run Dart programs directly without the run command:
# These are equivalent:
dart bin/main.dart
dart run bin/main.dart

VM Flags

When running Dart programs, you can pass flags to the VM:
# Enable asserts
dart --enable-asserts bin/main.dart

# Set heap size
dart --old-gen-heap-size=2048 bin/main.dart

# Enable observatory for debugging
dart --observe=8181 bin/main.dart

# List all VM options
dart --help --verbose

Experiments

Enable experimental language features:
# Enable a single experiment
dart --enable-experiment=macros run bin/main.dart

# Enable multiple experiments
dart --enable-experiment=macros,inline-class run bin/main.dart

# List available experiments
dart --enable-experiment=help

Environment Variables

DART_VM_OPTIONS

Set default VM options:
export DART_VM_OPTIONS="--enable-asserts --old-gen-heap-size=2048"
dart bin/main.dart

PUB_CACHE

Set the location of the package cache:
export PUB_CACHE="$HOME/.pub-cache"

Exit Codes

The dart command uses the following exit codes:
  • 0 - Success
  • 64 - Usage error (invalid arguments)
  • 65 - Command-specific error
  • 254 - Compilation error or file not found
  • 255 - Unexpected error

Configuration Files

analysis_options.yaml

Configure the analyzer and linter:
analyzer:
  exclude:
    - build/**
  errors:
    unused_import: error

linter:
  rules:
    - camel_case_types
    - prefer_const_constructors

pubspec.yaml

Define package metadata and dependencies:
name: my_app
description: A sample Dart application
version: 1.0.0

environment:
  sdk: ^3.0.0

dependencies:
  http: ^1.0.0

dev_dependencies:
  test: ^1.24.0

Examples

Development Workflow

# Create a new project
dart create my_app
cd my_app

# Get dependencies
dart pub get

# Analyze code
dart analyze

# Format code
dart format .

# Run tests
dart test

# Run the application
dart run bin/my_app.dart

# Compile to native executable
dart compile exe bin/my_app.dart -o build/my_app

Continuous Integration

#!/bin/bash
# CI script

# Install dependencies
dart pub get

# Verify formatting
dart format --output=none --set-exit-if-changed .

# Analyze code
dart analyze --fatal-infos

# Run tests with coverage
dart test --coverage=coverage

# Compile application
dart compile exe bin/main.dart -o build/app

See Also

Build docs developers (and LLMs) love