What Is Dart and How Do You Run It?
Dart is a programming language made by Google. It is designed to feel familiar to anyone who has written code before, while adding modern touches like strong typing and built-in safety features. You write plain text files containing Dart code, and a tool called the Dart SDK (Software Development Kit — the collection of programs needed to write and run Dart) turns that code into a running program.
Where Dart Is Used
Dart's most famous job is powering Flutter, Google's toolkit for building apps that run on phones, computers, and the web from one codebase. If you have used an app built with Flutter, you have used a Dart program. Dart also works well on its own for command-line tools, small servers, and scripts.
What Makes Dart Distinct
- Statically typed: every value has a type (like text, whole numbers, or true/false) that the computer checks before your program runs. This catches many mistakes early.
- Null safe: a value that might be "nothing" must be marked as such, so the language forces you to handle missing data carefully.
- Portable: the same Dart code can run on Windows, macOS, and Linux with no changes.
- Fast to start: you can run a Dart file directly, without a separate build step.
Installing the Dart SDK
- Visit the Dart website's install page (dart.dev).
- Follow the instructions for your operating system. On Windows, an installer is available; on macOS, a common option is
brew install dart; on Linux, packages are provided. - Open a new terminal and check that it worked:
dart --versionYou should see a version number. That command runs the Dart VM (the virtual machine — the engine that executes Dart code) and reports its version.
Running Your First Program
Create a file named hello.dart containing this line:
void main() {
print('Hello from Dart!');
}Here, main is the special starting point of every Dart program — the computer looks for it and begins there. print displays text on the screen.
Run it from your terminal:
dart run hello.dartYou should see:
Hello from Dart!That is the whole cycle: edit a .dart file, run it with one command, see the result. No extra setup or configuration is needed for small programs.
How a Dart Program Reaches the Screen
Show diagram source
flowchart LR
A["hello.dart (your code)"] --> B["dart run (command)"] --> C["Dart VM (executes it)"] --> D["Output on screen"]What Comes Next
In the next chapter, you will write a slightly bigger program and learn how Dart files are organized. After that, the tutorial builds up the language piece by piece: variables, decisions, functions, collections, and eventually classes and asynchronous code.
Exercise
What command do you use to run a Dart file called hello.dart, and what special function must every Dart program contain?
Show answer
Run it with dart run hello.dart. The program must contain a function named main, which is where execution begins.
Spotted a mistake, or code that does not work?