Watch the video (12 min)
On this page28 sections
  1. Prerequisites
  2. Connection With Previous Lectures
  3. Learning Objectives
  4. 1. What Is the Dart SDK?
  5. 2. Opening a Terminal
  6. 3. Three Ways to Get Dart
  7. 4. Installing on Windows
  8. 5. Installing on macOS
  9. 6. Installing on Linux
  10. 7. What PATH Means
  11. 8. Checking the Installation
  12. 9. Seeing What dart Can Do
  13. 10. Installing VS Code and the Dart Extension
  14. 11. Creating a Project with dart create
  15. 12. What's Inside the Project
  16. 13. Running a Project with dart run
  17. 14. Running One File
  18. 15. Changing the Program and Running Again
  19. 16. A Real-World Example
  20. Code Examples
  21. Common Beginner Mistakes
  22. Best Practices
  23. Mini Challenge
  24. Practice Questions
  25. Practice Answers
  26. Quick Revision
  27. Key Takeaways
  28. What's Next?

Lecture 02 — Dart SDK & Development Environment

Category1 — Dart Fundamentals
Lecture002 of 140
Estimated video length12 min
TargetDart 3.12.2
LevelBeginner

You know what Dart is, but your computer does not understand it yet. Installing the Dart SDK and an editor turns your machine into a place where Dart code can run.

Contents

Prerequisites · Connection · Objectives · Lesson · Code Examples · Common Mistakes · Best Practices · Mini Challenge · Practice Questions · Answers · Takeaways

Every terminal output and error message in this lecture is real. Each one was produced on a Mac (Apple silicon) running Dart 3.12.1. The Windows and Linux install steps are described rather than shown, because their output looks different on every machine. Once Dart is installed, the dart commands behave the same on all three systems.


Prerequisites

Students should already understand, from Lecture 001:

  • what Dart is and what it is used for
  • that a program is a set of instructions a computer follows

You also need a computer running Windows, macOS, or Linux, an internet connection, and permission to install software on it.


Connection With Previous Lectures

In Lecture 001 we saw what Dart can do. But if you type a line of Dart into a plain text file today and ask your computer to run it, nothing happens — the computer has no idea what Dart is.

output
zsh:1: command not found: dart

That message is what a computer without Dart says when you ask for it. Before we can write our first program, we need two things: the tools that understand Dart, and a comfortable place to type code. This lecture installs both.


Learning Objectives

By the end of this lecture you will be able to:

  • Explain what the Dart SDK is and what it contains
  • Open a terminal on your operating system
  • Install the Dart SDK on Windows, macOS, or Linux
  • Confirm the installation with dart --version
  • Set up VS Code with the Dart extension
  • Create a new project with dart create
  • Run a project and a single file with dart run
  • Recognize the messages Dart prints for common setup mistakes

1. What Is the Dart SDK?

An SDK (Software Development Kit) is a bundle of everything you need to build programs in one language. The Dart SDK contains the dart command, the engine that runs Dart code, Dart's built-in libraries, and helper tools for formatting, checking, and testing code.

Analogy — the SDK is a workshop toolbox. You do not buy a hammer, a saw, and a screwdriver separately; you get one box, and every tool inside is made to work together. The dart command is the handle you use to pick up any tool in the box.

You will use exactly one command for everything in this course: dart.


2. Opening a Terminal

A terminal is a window where you type commands instead of clicking buttons. All the commands in this lecture are typed there.

SystemHow to open it
WindowsPress Start, type PowerShell, press Enter
macOSPress Cmd + Space, type Terminal, press Enter
LinuxPress Ctrl + Alt + T on most desktops, or search for "Terminal"

In this lecture, a line you type is shown in a bash block, and what the computer prints back is shown in a text block below it.


3. Three Ways to Get Dart

OptionBest for
Install the Dart SDK (this lecture)Everyone following this course
Install FlutterPeople who will build apps later — Flutter includes a full Dart SDK
DartPad in a web browser (dartpad.dev)Trying a quick snippet when you cannot install anything

The machine used to write this lecture got its Dart from Flutter. Either way, the dart command behaves the same. DartPad is handy, but it cannot create projects, so install the SDK for this course.


4. Installing on Windows

The simplest route uses Chocolatey, a free package manager for Windows. After installing Chocolatey (see chocolatey.org), open PowerShell as Administrator and type:

bash
choco install dart-sdk

If you prefer not to use Chocolatey, download the Windows SDK .zip from the Dart website (dart.dev/get-dart), extract it to a folder such as C:\tools\dart-sdk, and add C:\tools\dart-sdk\bin to your PATH. Search Start for "environment variables", open Edit environment variables for your account, select Path, click Edit → New, and paste the folder.

Close PowerShell and open a new one before continuing.


5. Installing on macOS

On macOS, use Homebrew (see brew.sh if you do not have it yet). In Terminal:

bash
brew tap dart-lang/dart
brew install dart

The first line tells Homebrew where Dart's packages live; the second installs the SDK. Homebrew puts dart on your PATH for you.


6. Installing on Linux

On Ubuntu or Debian, add Google's Dart package source once, then install with apt:

bash
sudo apt-get update && sudo apt-get install apt-transport-https
wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub \
  | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' \
  | sudo tee /etc/apt/sources.list.d/dart_stable.list
sudo apt-get update && sudo apt-get install dart

The package installs Dart under /usr/lib/dart. If dart is not found afterwards, add /usr/lib/dart/bin to your PATH. On other distributions, use the Linux .zip from dart.dev/get-dart. Install commands change over time, so if a line fails, copy the current version from that page.


7. What PATH Means

When you type dart, your terminal searches a list of folders called the PATH for a program with that name. If the SDK's bin folder is not on that list, the terminal gives up:

bash
dart --version
output
zsh:1: command not found: dart

On Windows PowerShell the wording is different (The term 'dart' is not recognized…), but the meaning is the same. The fix is always one of two things: add the SDK's bin folder to PATH, or simply open a new terminal — a terminal that was already open before the install still has the old list.


8. Checking the Installation

This is the most important command in the lecture. Run it in a new terminal:

bash
dart --version
output
Dart SDK version: 3.12.1 (stable) (Tue May 26 01:02:21 2026 -0700) on "macos_arm64"

Read it left to right: the version number, the stable release channel, the build date, and your platform — here, macOS on an ARM (Apple silicon) chip. On Windows you would see something like windows_x64. Any 3.12 version works for this course, and a newer one is fine too.


9. Seeing What dart Can Do

The dart command contains many tools. Ask it to list them:

bash
dart --help
output
A command-line utility for Dart development.

Usage: dart <command|dart-file> [arguments]
...
Available commands:
...
Project
  build       Build a Dart application including code assets.
  compile     Compile Dart to various formats.
  create      Create a new Dart project.
  pub         Work with packages.
  run         Run a Dart program from a file or a local or remote package.
  test        Run tests for a project.

Source code
  analyze     Analyze Dart code in a directory.
  doc         Generate API documentation for Dart projects.
  fix         Apply automated fixes to Dart source code.
  format      Idiomatically format Dart source code.
...

The list is trimmed here (...). Today we need only create and run. We will tour the rest in Lecture 113 — Dart CLI.


10. Installing VS Code and the Dart Extension

You can write Dart in any text editor, but VS Code (free, from code.visualstudio.com) with the official Dart extension makes it far easier.

  1. Download and install VS Code for your system.
  2. Open the Extensions view: Ctrl + Shift + X (Windows/Linux) or Cmd + Shift + X (macOS).
  3. Search for Dart and install the extension published by Dart Code.

The extension colors your code, underlines mistakes in red as you type, formats your code, and adds Run | Debug links above your program's starting point. VS Code also has a built-in terminal (View → Terminal), so you can run every command in this lecture without leaving the editor.


11. Creating a Project with dart create

A project is a folder that holds a program's code and its settings. First move to a folder where you keep your work (for example, cd Documents), then run:

bash
dart create hello_dart
output
Creating hello_dart using template console...

  .gitignore
  analysis_options.yaml
  CHANGELOG.md
  pubspec.yaml
  README.md
  bin/hello_dart.dart
  lib/hello_dart.dart
  test/hello_dart_test.dart

Running pub get...
  Resolving dependencies...
  Downloading packages...
  Changed 50 dependencies!

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

  cd hello_dart
  dart run

Dart created a folder called hello_dart, filled it with starter files, and downloaded the helper packages the project uses. That download needs an internet connection the first time.


12. What's Inside the Project

Open the folder in VS Code with File → Open Folder…. These are the parts that matter now:

ItemPurpose
bin/hello_dart.dartThe program that runs — this is where you will write code
lib/hello_dart.dartCode that other files can share
test/hello_dart_test.dartCode that checks other code works
pubspec.yamlThe project's name, Dart version, and packages it uses

The starter program in bin/hello_dart.dart looks like this:

dart
import 'package:hello_dart/hello_dart.dart' as hello_dart;

void main(List<String> arguments) {
  print('Hello world: ${hello_dart.calculate()}!');
}

Do not worry about what each word means yet. We will write our own program line by line in Lecture 003, study pubspec.yaml in Lecture 104, and write tests in Lecture 118 — Introduction to Testing.


13. Running a Project with dart run

Move into the project folder and run it:

bash
cd hello_dart
dart run
output
Hello world: 42!

Inside a project, a plain dart run finds the program in bin/ and runs it. The 42 comes from a small calculation in lib/hello_dart.dart.


14. Running One File

dart run can also run a single file by name — inside a project or anywhere else. Save this as hello.dart in any folder:

dart
void main() {
  print('Hello, Dart!');
}
bash
dart run hello.dart
output
Hello, Dart!

A single file is perfect for quick experiments. A project is better once a program grows past one file.


15. Changing the Program and Running Again

Programming is a loop: edit, save, run. Replace everything in bin/hello_dart.dart with:

dart
void main() {
  print('Hello, Ali!');
}

Save the file (Ctrl + S / Cmd + S), then run the project again:

bash
dart run
output
Hello, Ali!

In VS Code you can also click the Run link above void main(); the output appears in the editor's Debug Console panel instead of the terminal. Debugging itself is covered in Lecture 115 — Debugging Dart.


16. A Real-World Example

Let's use the whole workflow once more. Sara wants a program that totals her shopping.

bash
dart create shopping_total
cd shopping_total

Replace everything in bin/shopping_total.dart with:

dart
void main() {
  print('Shopping list for Sara');
  print('Notebooks: 3 x 500');
  print('Pens: 4 x 50');
  print('Total:');
  print(3 * 500 + 4 * 50);
}
bash
dart run
output
Shopping list for Sara
Notebooks: 3 x 500
Pens: 4 x 50
Total:
1700

That is the full cycle you will repeat for the rest of the course: create, edit, save, run, read the output.


Code Examples

Each example is a command to type or a small program to save and run. Programs use only print(); Lecture 003 explains every line of them.

Example 1 — Checking the Version

bash
dart --version
output
Dart SDK version: 3.12.1 (stable) (Tue May 26 01:02:21 2026 -0700) on "macos_arm64"

Your version, date, and platform may differ. What matters is that you see a version instead of command not found.

Example 2 — Getting Help

bash
dart --help
output
A command-line utility for Dart development.

Usage: dart <command|dart-file> [arguments]
...

The first lines show the general shape of every dart command: the word dart, then a command or a file, then any extra details.

Example 3 — Creating a Project

bash
dart create first_app
output
Creating first_app using template console...
...
Created project first_app in first_app! In order to get started, run the following commands:

  cd first_app
  dart run

The project's folder takes the name you give. Dart even tells you the next two commands.

Example 4 — Running a Project

bash
cd first_app
dart run
output
Hello world: 42!

Every new console project prints this same line until you change it.

Example 5 — Running a File Inside a Project by Path

bash
dart run bin/first_app.dart
output
Hello world: 42!

Same result as Example 4. Here you named the file explicitly instead of letting Dart find it.

Example 6 — A Single-File Program

Save as hello.dart:

dart
void main() {
  print('Hello, Dart!');
}
bash
dart run hello.dart
output
Hello, Dart!

No project needed: one file, one command.

Example 7 — Student Marks

Save as marks.dart:

dart
void main() {
  print('Ali, total marks:');
  print(80 + 75 + 85);
}
bash
dart run marks.dart
output
Ali, total marks:
240

How it works

  1. The first print shows the text between the quotes exactly as written.
  2. The second print has no quotes, so Dart calculates 80 + 75 + 85 and shows 240.
  3. Each print starts a new line.

Example 8 — Shopping Total

Save as shopping.dart:

dart
void main() {
  print('Notebooks: 3 x 500');
  print(500 * 3);
}
bash
dart run shopping.dart
output
Notebooks: 3 x 500
1500

How it works

  1. Inside quotes, 3 x 500 is just text — Dart does not calculate it.
  2. In Dart code, multiplication is written with *, not x.
  3. 500 * 3 is calculated and printed as 1500.

Example 9 — Bank Balance

Save as balance.dart:

dart
void main() {
  print('Balance after a 250 purchase:');
  print(1000 - 250);
}
bash
dart run balance.dart
output
Balance after a 250 purchase:
750

How it works

  1. The label is printed as text.
  2. 1000 - 250 is calculated as 750.
  3. Change 250 to another amount, save, and run again — the edit-save-run loop in action.

Example 10 — Temperature Conversion

Save as temperature.dart:

dart
void main() {
  print('25 degrees Celsius in Fahrenheit:');
  print(25 * 9 / 5 + 32);
}
bash
dart run temperature.dart
output
25 degrees Celsius in Fahrenheit:
77.0

How it works

  1. Dart multiplies and divides first: 25 * 9 / 5 is 45.
  2. Then it adds 32, giving 77.
  3. It prints 77.0 because division (/) always produces a decimal number. We will study whole and decimal numbers in Lecture 009 — Numbers.

Common Beginner Mistakes

1. Using a terminal that was open before the install

bash
dart --version
output
zsh:1: command not found: dart

Close the terminal and open a new one. If the message stays, the SDK's bin folder is not on your PATH — revisit the install step for your system.

2. Misspelling a command

bash
dart versoin
output
Could not find a command named "versoin".

Usage: dart <command|dart-file> [arguments]

Dart lists the commands it does know right below this message. Check the spelling.

3. Running dart run outside the project folder

bash
dart run
output
Found no `pubspec.yaml` file in `<your folder>` or parent directories

(Dart prints the full path of the folder you are in; it is shortened here.) A plain dart run needs a project. Use cd to move into the project folder first.

4. Mistyping a file name

bash
dart run missing.dart
output
Could not find file `missing.dart`

Check the spelling, and check that you are in the folder that contains the file.

5. Creating a project whose folder already exists

bash
dart create hello_dart
output
Directory '<your folder>/hello_dart' already exists (use '--force' to force project generation).

Choose a different name. Do not reach for --force — it can overwrite files you wrote.

6. Forgetting a semicolon after editing

Running this hello.dart:

dart
// void main() {
//   print('Hello, Ali!')   ✗ missing ;
// }
output
hello.dart:2:22: Error: Expected ';' after this.
  print('Hello, Ali!')
                     ^

The error names the file, the line (2), and the column (22). Add the ; and run again.

7. Running before saving

If the output has not changed after an edit, you probably did not save. VS Code shows a dot on the file's tab when it has unsaved changes.


Best Practices

  • Always run dart --version in a new terminal right after installing.
  • Install the official extension published by Dart Code — not a look-alike.
  • Name projects in lowercase_with_underscores, such as shopping_total.
  • Keep all your course projects together in one folder, so they are easy to find.
  • Write your code in bin/; leave lib/ and test/ alone until later lectures.
  • Save before every run — or turn on File → Auto Save in VS Code.
  • Read error messages fully: they tell you the file, line, and column.

Mini Challenge

Create a project called marks_report. Make it print exactly:

output
Student: Ali
Total marks:
240

The 240 must be calculated by Dart from the marks 80, 75, and 85, not typed in.

Try it yourself before opening the solution.

Show solution
bash
dart create marks_report
cd marks_report

Replace everything in bin/marks_report.dart with:

dart
void main() {
  print('Student: Ali');
  print('Total marks:');
  print(80 + 75 + 85);
}
bash
dart run
output
Student: Ali
Total marks:
240

How it works

  1. dart create builds the project folder and starter files.
  2. The new program replaces the starter code completely.
  3. The third print has no quotes, so Dart calculates the total.

Practice Questions

Work through these in order — they run from beginner to application to challenge.

Beginner

  1. Which command shows the version of Dart installed on your computer?
  2. Which command lists every tool the dart command contains?
  3. Create a new console project named first_app. What command do you type?

Application

  1. Run the first_app project without changing anything. What does it print?
  2. Without creating a project, write and run a single file greeting.dart that prints Hello, Sara!.
  3. Change first_app so that it prints Welcome, Zayan! instead of its starter message.
  4. You type dart run and see Found no pubspec.yaml file in …. What went wrong, and how do you fix it?
  5. Write and run a single file shopping.dart that calculates and prints the cost of 4 items at 250 each.

Challenge

  1. Inside the first_app folder, run the program by naming its file directly rather than with a plain dart run.
  2. A friend installs Dart, then types dart --version in a terminal that was already open and gets command not found. List the two things to check, in order.

Practice Answers

Question 1 — Solution

bash
dart --version
output
Dart SDK version: 3.12.1 (stable) (Tue May 26 01:02:21 2026 -0700) on "macos_arm64"

Your own version, date, and platform will differ.

Question 2 — Solution

bash
dart --help
output
A command-line utility for Dart development.

Usage: dart <command|dart-file> [arguments]
...

Question 3 — Solution

bash
dart create first_app
output
Creating first_app using template console...
...
Created project first_app in first_app! In order to get started, run the following commands:

  cd first_app
  dart run

Question 4 — Solution

bash
cd first_app
dart run
output
Hello world: 42!

Question 5 — Solution

Save as greeting.dart:

dart
void main() {
  print('Hello, Sara!');
}
bash
dart run greeting.dart
output
Hello, Sara!

Question 6 — Solution

Replace everything in bin/first_app.dart with:

dart
void main() {
  print('Welcome, Zayan!');
}
bash
dart run
output
Welcome, Zayan!

Question 7 — Solution

You ran dart run in a folder that is not a project. Move into the project folder first — for example, first_app after the change in Question 6:

bash
cd first_app
dart run
output
Welcome, Zayan!

Question 8 — Solution

Save as shopping.dart:

dart
void main() {
  print(250 * 4);
}
bash
dart run shopping.dart
output
1000

Question 9 — Solution

bash
dart run bin/first_app.dart
output
Welcome, Zayan!

It prints Welcome, Zayan! because of the change made in Question 6. Before that change, it would print Hello world: 42!.

Question 10 — Solution

First, close the terminal, open a new one, and try again:

bash
dart --version
output
Dart SDK version: 3.12.1 (stable) (Tue May 26 01:02:21 2026 -0700) on "macos_arm64"

If it still says command not found, the SDK's bin folder is not on the PATH. Add it (see the install step for your system), open another new terminal, and run dart --version again.


Quick Revision

  1. What does SDK stand for, and what does the Dart SDK contain?
  2. What is the PATH, and what happens when dart is not on it?
  3. Which command confirms that Dart is installed?
  4. Which VS Code extension do you install for Dart, and who publishes it?
  5. What does dart create do?
  6. In which folder of a new project do you write your program?
  7. What is the difference between dart run and dart run hello.dart?
  8. Why might your output stay the same after you edit the code?

Key Takeaways

  • The Dart SDK is the toolbox; the dart command is how you use every tool in it.
  • Install with Chocolatey or a .zip on Windows, Homebrew on macOS, and apt or a .zip on Linux. Flutter also includes Dart.
  • command not found means the terminal cannot find dart — open a new terminal, then check your PATH.
  • dart --version confirms the install; dart --help lists every tool.
  • VS Code with the Dart extension (by Dart Code) is the editor for this course.
  • dart create name builds a project; your code lives in bin/.
  • dart run runs a project; dart run file.dart runs a single file.
  • The working loop is edit, save, run, read the output.

What's Next?

Lecture 03 — Your First Dart Program & Comments. Your tools are ready, and you have already run a few programs by copying them. Next we will write a program from an empty file and understand every part of it — main(), print(), statements, and semicolons — and learn how comments let you leave notes in your code that Dart ignores.


Video lecture

Subscribe
Placeholder video — the real recording isn't linked yet.