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] <script_path> [SCRIPT_ARGUMENTS]
dart [GLOBAL_OPTIONS] <command> [COMMAND_OPTIONS] [COMMAND_ARGUMENTS]

PARAMETERS

-h, --help
    Displays general help information or help for a specific subcommand.

--version
    Prints the Dart SDK version information.

--enable-asserts
    Enables the execution of assert statements in Dart code when running scripts.

--observe[=<port>/<host>:<port>]
    Enables the Dart VM service and opens the Observatory debugger/profiler, often with an optional port or host:port.

--disable-service-auth-codes
    Disables the use of authentication codes for the Dart VM service, primarily for development or trusted environments.

--packages=<path>
    Specifies the path to the .packages file, which maps package names to URIs for package resolution.

--enable-debugging
    Enables debugging for the Dart VM, allowing debuggers to attach.

--profile
    Enables CPU profiling during execution, collecting performance data.

--current-directory=<path>
    Sets the current working directory for the Dart process, affecting relative path resolution.

--verbosity=<level>
    Sets the verbosity level for logs (e.g., all, warning, error) from the Dart VM.

--enable-experiment=<name>
    Enables a specific experimental Dart language feature, often requiring an SDK restart.

DESCRIPTION

The dart command is the primary command-line interface for interacting with the Dart SDK. It serves as a versatile tool for Dart developers, enabling them to

run Dart scripts directly,
compile Dart source code into native executables for various platforms (Windows, macOS, Linux, ARM) or JavaScript for web deployment,
test Dart applications,
manage packages using the integrated pub subcommand,
and perform many other development tasks such as code analysis, formatting, documentation generation, and debugging.

It leverages the Dart Virtual Machine (VM) for fast, JIT-compiled execution during development and can also create optimized, AOT-compiled executables for production deployment, offering flexibility for different development and deployment needs across mobile (Flutter), web, desktop, and server environments.

CAVEATS

The dart command is not a standard core Linux utility; it requires the Dart SDK to be installed and correctly configured in the system's PATH.

Its functionality is highly dependent on the subcommand invoked (e.g., run, compile, pub), and the options available often vary significantly between these subcommands.

Direct execution of Dart scripts (dart script.dart) defaults to JIT compilation, which is optimized for fast development cycles but may have a larger memory footprint and slower startup than AOT-compiled native executables produced by dart compile.

COMMON SUBCOMMANDS

The dart command acts as a dispatcher for various essential subcommands, each providing distinct functionality:

run: Executes a Dart application or script.
compile: Compiles Dart source code into native executables or JavaScript.
test: Runs tests defined for a Dart project.
pub: Manages packages (e.g., pub get, pub upgrade, pub publish).
create: Generates new Dart project templates (e.g., console app, web app).
fix: Applies automated fixes to Dart source code.
format: Formats Dart source code according to style guidelines.
analyze: Analyzes Dart code for errors, warnings, and style issues.

Each subcommand has its own set of specific options and arguments, which can be viewed using dart help <subcommand_name>.

HISTORY

The Dart programming language and its SDK, including the dart command, were developed by Google.

Initially unveiled in 2011, Dart was conceived as an alternative to JavaScript for web development. While its direct adoption in browsers didn't materialize as broadly intended, Dart found significant success and renewed focus with the advent of the Flutter UI toolkit in 2017. Flutter's rise, especially for cross-platform mobile development, propelled Dart into widespread use across mobile, web, desktop, and backend environments.

The dart command has evolved alongside the language and SDK, growing from a simple script runner to a comprehensive development hub for the entire Dart ecosystem, integrating build, test, and package management functionalities.

SEE ALSO

node(1), python3(1), flutter(1), pub(1)

Copied to clipboard