LinuxCommandLibrary

dart

Run Dart programs

TLDR

Initialize a new Dart project in a directory of the same name

$ dart create [project_name]
copy

Run a Dart file
$ dart run [path/to/file.dart]
copy

Download dependencies for the current project
$ dart pub get
copy

Run unit tests for the current project
$ dart test
copy

Update an outdated project's dependencies to support null-safety
$ dart pub upgrade --null-safety
copy

Compile a Dart file to a native binary
$ dart compile exe [path/to/file.dart]
copy

Apply automated fixes to the current project
$ dart fix --apply
copy

SYNOPSIS

dart [vm-options] <command> [arguments] | <script.dart> [arguments]

PARAMETERS

--help
    Display usage information

--version
    Print Dart version

--enable-asserts
    Enable assertions

--enable-experiment=<name>
    Enable language experiments

--enable-service-port-fallback
    Fallback for VM service port

--enable-vm-service
    Enable VM service

--lazy-async-stack-traces
    Enable lazy async stack traces

--mute-core-library-messages
    Mute core library messages

--no-pub
    Disable pub package resolution

--packages=<path>
    Path to package resolution config

--pause-isolates-on-exit
    Pause isolates on exit

--pause-isolates-on-start
    Pause isolates on start

--profiler
    Enable profiler

--sound-null-safety
    Enforce sound null safety

--verbosity=<level>
    Set output verbosity (all|error|warning|info|normal)

DESCRIPTION

The dart command is the primary entry point to the Dart SDK on Linux, providing a versatile CLI for developing, running, compiling, and managing Dart applications. Dart is a modern, object-oriented language optimized for client-side development, supporting both just-in-time (JIT) and ahead-of-time (AOT) compilation for platforms like web, mobile, server, and desktop.

It supports running Dart scripts directly (dart example.dart), executing subcommands for tasks like code analysis (dart analyze), compilation (dart compile exe), package management via pub (dart pub get), testing (dart test), and formatting (dart format). Global options allow customization such as enabling assertions, experiments, or service ports for debugging.

Ideal for Flutter developers (as Flutter apps are Dart-based), it integrates with IDEs like VS Code and enables cross-platform builds. Requires Dart SDK installation via official binaries or package managers like snap or apt.

CAVEATS

Requires Dart SDK installation; not in standard repos (use snap/flatpak or binaries). Subcommands like pub need internet for dependencies. JIT mode slower than AOT for production.

COMMON SUBCOMMANDS

analyze: Static analysis; compile: AOT compilation (exe/js); run: Execute script; pub: Manage packages; test: Run tests; format: Format code.

INSTALLATION ON LINUX

Download from dart.dev/get-dart; extract and add bin/ to PATH. Or snap install dart-sdk --classic.

HISTORY

Announced by Google in 2011, Dart 1.0 released 2013. Dart 2.0 (2018) introduced sound typing; 2.12 (2021) added sound null safety. CLI evolved with SDK, now at 3.x supporting Wasm and cross-compilation.

SEE ALSO

node(1), python3(1), go(1), flutter(1)

Copied to clipboard