On this page28 sections
- Prerequisites
- Connection With Previous Lectures
- Learning Objectives
- 1. What Is the Dart SDK?
- 2. Opening a Terminal
- 3. Three Ways to Get Dart
- 4. Installing on Windows
- 5. Installing on macOS
- 6. Installing on Linux
- 7. What PATH Means
- 8. Checking the Installation
- 9. Seeing What dart Can Do
- 10. Installing VS Code and the Dart Extension
- 11. Creating a Project with dart create
- 12. What's Inside the Project
- 13. Running a Project with dart run
- 14. Running One File
- 15. Changing the Program and Running Again
- 16. A Real-World Example
- Code Examples
- Common Beginner Mistakes
- Best Practices
- Mini Challenge
- Practice Questions
- Practice Answers
- Quick Revision
- Key Takeaways
- What's Next?
Lecture 02 — Dart SDK & Development Environment
| Category | 1 — Dart Fundamentals |
| Lecture | 002 of 140 |
| Estimated video length | 12 min |
| Target | Dart 3.12.2 |
| Level | Beginner |
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
dartcommands 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.
zsh:1: command not found: dartThat 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
dartcommand 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.
| System | How to open it |
|---|---|
| Windows | Press Start, type PowerShell, press Enter |
| macOS | Press Cmd + Space, type Terminal, press Enter |
| Linux | Press 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
| Option | Best for |
|---|---|
| Install the Dart SDK (this lecture) | Everyone following this course |
| Install Flutter | People 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:
choco install dart-sdkIf 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:
brew tap dart-lang/dart
brew install dartThe 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:
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 dartThe 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:
dart --versionzsh:1: command not found: dartOn 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:
dart --versionDart 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:
dart --helpA 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.
- Download and install VS Code for your system.
- Open the Extensions view: Ctrl + Shift + X (Windows/Linux) or Cmd + Shift + X (macOS).
- 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:
dart create hello_dartCreating 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 runDart 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:
| Item | Purpose |
|---|---|
bin/hello_dart.dart | The program that runs — this is where you will write code |
lib/hello_dart.dart | Code that other files can share |
test/hello_dart_test.dart | Code that checks other code works |
pubspec.yaml | The project's name, Dart version, and packages it uses |
The starter program in bin/hello_dart.dart looks like this:
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:
cd hello_dart
dart runHello 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:
void main() {
print('Hello, Dart!');
}dart run hello.dartHello, 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:
void main() {
print('Hello, Ali!');
}Save the file (Ctrl + S / Cmd + S), then run the project again:
dart runHello, 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.
dart create shopping_total
cd shopping_totalReplace everything in bin/shopping_total.dart with:
void main() {
print('Shopping list for Sara');
print('Notebooks: 3 x 500');
print('Pens: 4 x 50');
print('Total:');
print(3 * 500 + 4 * 50);
}dart runShopping list for Sara
Notebooks: 3 x 500
Pens: 4 x 50
Total:
1700That 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
dart --versionDart 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
dart --helpA 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
dart create first_appCreating 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 runThe project's folder takes the name you give. Dart even tells you the next two commands.
Example 4 — Running a Project
cd first_app
dart runHello world: 42!Every new console project prints this same line until you change it.
Example 5 — Running a File Inside a Project by Path
dart run bin/first_app.dartHello 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:
void main() {
print('Hello, Dart!');
}dart run hello.dartHello, Dart!No project needed: one file, one command.
Example 7 — Student Marks
Save as marks.dart:
void main() {
print('Ali, total marks:');
print(80 + 75 + 85);
}dart run marks.dartAli, total marks:
240How it works
- The first
printshows the text between the quotes exactly as written. - The second
printhas no quotes, so Dart calculates80 + 75 + 85and shows240. - Each
printstarts a new line.
Example 8 — Shopping Total
Save as shopping.dart:
void main() {
print('Notebooks: 3 x 500');
print(500 * 3);
}dart run shopping.dartNotebooks: 3 x 500
1500How it works
- Inside quotes,
3 x 500is just text — Dart does not calculate it. - In Dart code, multiplication is written with
*, notx. 500 * 3is calculated and printed as1500.
Example 9 — Bank Balance
Save as balance.dart:
void main() {
print('Balance after a 250 purchase:');
print(1000 - 250);
}dart run balance.dartBalance after a 250 purchase:
750How it works
- The label is printed as text.
1000 - 250is calculated as750.- Change
250to another amount, save, and run again — the edit-save-run loop in action.
Example 10 — Temperature Conversion
Save as temperature.dart:
void main() {
print('25 degrees Celsius in Fahrenheit:');
print(25 * 9 / 5 + 32);
}dart run temperature.dart25 degrees Celsius in Fahrenheit:
77.0How it works
- Dart multiplies and divides first:
25 * 9 / 5is45. - Then it adds
32, giving77. - It prints
77.0because 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
dart --versionzsh:1: command not found: dartClose 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
dart versoinCould 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
dart runFound 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
dart run missing.dartCould 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
dart create hello_dartDirectory '<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:
// void main() {
// print('Hello, Ali!') ✗ missing ;
// }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 --versionin 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/; leavelib/andtest/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:
Student: Ali
Total marks:
240The 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
dart create marks_report
cd marks_reportReplace everything in bin/marks_report.dart with:
void main() {
print('Student: Ali');
print('Total marks:');
print(80 + 75 + 85);
}dart runStudent: Ali
Total marks:
240How it works
dart createbuilds the project folder and starter files.- The new program replaces the starter code completely.
- The third
printhas no quotes, so Dart calculates the total.
Practice Questions
Work through these in order — they run from beginner to application to challenge.
Beginner
- Which command shows the version of Dart installed on your computer?
- Which command lists every tool the
dartcommand contains? - Create a new console project named
first_app. What command do you type?
Application
- Run the
first_appproject without changing anything. What does it print? - Without creating a project, write and run a single file
greeting.dartthat printsHello, Sara!. - Change
first_appso that it printsWelcome, Zayan!instead of its starter message. - You type
dart runand seeFound no pubspec.yaml file in …. What went wrong, and how do you fix it? - Write and run a single file
shopping.dartthat calculates and prints the cost of4items at250each.
Challenge
- Inside the
first_appfolder, run the program by naming its file directly rather than with a plaindart run. - A friend installs Dart, then types
dart --versionin a terminal that was already open and getscommand not found. List the two things to check, in order.
Practice Answers
Question 1 — Solution
dart --versionDart 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
dart --helpA command-line utility for Dart development.
Usage: dart <command|dart-file> [arguments]
...Question 3 — Solution
dart create first_appCreating 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 runQuestion 4 — Solution
cd first_app
dart runHello world: 42!Question 5 — Solution
Save as greeting.dart:
void main() {
print('Hello, Sara!');
}dart run greeting.dartHello, Sara!Question 6 — Solution
Replace everything in bin/first_app.dart with:
void main() {
print('Welcome, Zayan!');
}dart runWelcome, 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:
cd first_app
dart runWelcome, Zayan!Question 8 — Solution
Save as shopping.dart:
void main() {
print(250 * 4);
}dart run shopping.dart1000Question 9 — Solution
dart run bin/first_app.dartWelcome, 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:
dart --versionDart 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
- What does SDK stand for, and what does the Dart SDK contain?
- What is the PATH, and what happens when
dartis not on it? - Which command confirms that Dart is installed?
- Which VS Code extension do you install for Dart, and who publishes it?
- What does
dart createdo? - In which folder of a new project do you write your program?
- What is the difference between
dart runanddart run hello.dart? - Why might your output stay the same after you edit the code?
Key Takeaways
- The Dart SDK is the toolbox; the
dartcommand is how you use every tool in it. - Install with Chocolatey or a
.zipon Windows, Homebrew on macOS, and apt or a.zipon Linux. Flutter also includes Dart. command not foundmeans the terminal cannot finddart— open a new terminal, then check your PATH.dart --versionconfirms the install;dart --helplists every tool.- VS Code with the Dart extension (by Dart Code) is the editor for this course.
dart create namebuilds a project; your code lives inbin/.dart runruns a project;dart run file.dartruns 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.