TExcelTAD
Home › Dart › Dart Get Started

Dart Get Started

You can run every example in this course right in the browser. Sooner or later, though, you will want Dart on your own machine. This lesson shows how to install the SDK, create a project and run it.

Install the Dart SDK

The SDK contains the compiler, the virtual machine, the core libraries and the dart command-line tool.

System Command
Windows choco install dart-sdk (or download the ZIP from dart.dev)
macOS brew tap dart-lang/dart then brew install dart
Linux (Debian/Ubuntu) add Google's apt repository, then sudo apt install dart
Already have Flutter? Nothing to do — Flutter bundles Dart (flutter/bin/dart)

Check that it works:

bash · try it yourself
dart --version
Dart SDK version: 3.7.3 (stable) on "linux_x64"

Note: The terminal examples in this lesson are simulated — they show what you would see on your own computer.

Create a project

dart create generates a ready-to-run project. The default template is a command-line app.

bash · try it yourself
dart create greeter
Creating greeter using template console...

  .gitignore
  analysis_options.yaml
  CHANGELOG.md
  pubspec.yaml
  README.md
  bin/greeter.dart
  lib/greeter.dart
  test/greeter_test.dart

Running pub get...
  Resolving dependencies...
  Changed 46 dependencies!

Created project greeter in greeter! In order to get started, run the following commands:

  cd greeter
  dart run

The important files:

Path Purpose
pubspec.yaml Project name, SDK constraint and dependencies
bin/greeter.dart The entry point containing main
lib/ Reusable library code, imported by bin/ and test/
test/ Unit tests run with dart test
analysis_options.yaml Lint rules used by the analyzer

A minimal pubspec.yaml looks like this:

yaml
name: greeter
description: A sample command-line application.
version: 1.0.0

environment:
  sdk: ^3.7.0

dev_dependencies:
  lints: ^5.0.0
  test: ^1.24.0

Run the program

Inside the project folder, dart run compiles and runs bin/<project>.dart:

bash · try it yourself
cd greeter
dart run
Building package executable...
Built greeter:greeter.
Hello world: 42!

You can also run any single file directly — handy for quick experiments:

bash
dart run hello.dart

Here is a script you could save as hello.dart. It reads command-line arguments through the optional args parameter of main:

dart · try it yourself
void main(List<String> args) {
  final name = args.isEmpty ? 'world' : args.first;
  print('Hello, $name!');
  print('You passed ${args.length} argument(s).');
}
Hello, world!
You passed 0 argument(s).

Running it as dart run hello.dart Lan would print Hello, Lan! and You passed 1 argument(s).

The everyday toolbox

Command What it does
dart run Run a program with the JIT VM (fast startup while developing)
dart compile exe bin/app.dart Build a self-contained native executable (AOT)
dart compile js / dart compile wasm Compile for the browser
dart format . Format all files in the official style
dart analyze Report errors, warnings and lint hints
dart fix --apply Automatically apply suggested fixes
dart test Run the tests in test/
dart pub add <package> Add a dependency from pub.dev
bash · try it yourself
dart compile exe bin/greeter.dart -o greeter
./greeter
Generated: /home/lan/greeter/greeter
Hello world: 42!

The executable runs without the SDK installed — perfect for distributing CLI tools.

Editors

Install the official Dart extension for VS Code or the Dart plugin for IntelliJ/Android Studio. You get completion, inline errors, quick fixes, formatting on save and a debugger.

Tip: Turn on "format on save". dart format settles all style debates, and every Dart codebase you read will look the same.

Test yourself

Which command creates a new Dart console project?

  1. dart new app
  2. dart init
  3. dart create app
  4. pub create app

Which file lists a package's dependencies?

  1. package.json
  2. pubspec.yaml
  3. analysis_options.yaml
  4. dart.toml

What does dart compile exe produce?

  1. A JavaScript bundle
  2. A self-contained native executable
  3. A .jar file
  4. Bytecode for the JIT