Learn Dart - Installation & Running Dart
Series/Learn Dart/Episode 3
Episode 3 of 23

Learn Dart - Installation & Running Dart

This episode is hands-on: installing the Dart SDK and verifying the version, running scripts with dart run and the dart repl REPL, creating a project with dart create, and adding your first dependency to pubspec.yaml.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

In episode 2 you already understood Dart's architecture. Now it's time to get your hands on the terminal. Episode 3 is a full practice session: installing the Dart SDK, verifying the installation, running scripts, using the REPL, creating a project, and adding your first dependency.

This entire series will use the same commands, so make sure you follow these steps on your own machine. Don't hesitate to repeat them until the commands feel natural under your fingers.

The end goal of this episode is simple: you can create a new Dart project and add a package from pub.dev without looking at the documentation.

Installing the Dart SDK

Installation Options per Operating System

The Dart SDK can be installed in several ways:

  • Linux (apt): official packages from the Google repository, installed with apt.
  • macOS (Homebrew): just brew install dart.
  • Windows (Chocolatey): choco install dart-sdk, or download the zip from dart.dev.

A universal alternative: download the Dart SDK archive directly from the official site and add the bin directory to your PATH. This gives you full control over the version.

Installation Verification

After installation, verify that the command is recognized by your shell:

Verify the Dart version
dart --version

The output shows the SDK version and the target architecture, for example Dart SDK version: 3.5.4 (stable). If command not found appears, double-check your PATH and make sure the shell was restarted after installation. The command dart --version will be your first health check every time you set up a new environment.

Running Dart Scripts

dart run for a Single File

The easiest way to execute code is to write a single file and run it:

Simple hello script
void main() {
  var pesan = 'Dart siap dipakai';
  print(pesan);
}
Run a script with dart run
dart run hello.dart

dart run hello.dart runs the script with the Dart VM. For a project, dart run without arguments executes the entry point registered in pubspec.yaml.

REPL with dart repl

For quick experiments, use the REPL (Read-Eval-Print Loop):

Enter the Dart REPL
dart repl

Inside the REPL, you can type expressions and immediately see the results without creating a file. Type exit to leave. The REPL is very useful for testing syntax before adding it to a project.

Creating a Project with dart create

For a real project, don't create files manually. Use the official scaffold:

Create a console project
dart create my_app
cd my_app

The command dart create my_app generates a console project with a standard structure: bin/ for the entry point, lib/ for importable code, and test/ for unit tests. Various templates are available, including package for libraries and server-shelf for backend applications.

Run the bundled project to make sure everything works:

Run the new project
dart run

The output shows the message from bin/my_app.dart. This structure is the foundation of every Dart project you'll encounter.

Adding a Dependency to pubspec.yaml

Understanding pubspec.yaml

All project metadata lives in pubspec.yaml. This file declares the name, SDK environment, dependencies, and dev_dependencies:

Example pubspec.yaml
name: my_app
description: Contoh project Dart.
version: 1.0.0
 
environment:
  sdk: ^3.5.0
 
dependencies:
  http: ^1.2.0
 
dev_dependencies:
  lints: ^4.0.0
  test: ^1.25.0

In the example above, the http dependency is written with the caret version ^1.2.0, which means version 1.2.0 up to but not including 2.0.0. Dependencies are added in the dependencies block, while development tooling goes into dev_dependencies.

Downloading Dependencies with dart pub get

After editing pubspec.yaml, download the dependencies:

Fetch dependencies
dart pub get

The command dart pub get downloads all dependencies and creates a pubspec.lock file that pins the exact versions. Re-run this command every time pubspec.yaml changes, and the downloads are stored in the .dart_tool/ directory.

Conclusion

Key takeaways:

  • Install the Dart SDK via apt, Homebrew, Chocolatey, or the official archive.
  • Always verify with dart --version after a fresh setup.
  • dart run file_name.dart for a single script; dart run for a project entry point.
  • dart repl for quick experiments without creating files.
  • dart create scaffolds a standard project structure with bin, lib, and test.
  • Add dependencies in pubspec.yaml, then run dart pub get.

In the next episode 4, we'll move into syntax and basic language features — variables with var, final, and const, control flow like if, switch, and loops, functions with optional parameters, and the List, Set, and Map collections. You'll start writing real Dart code.

Learn Dart - Installation & Running Dart | Learn Dart