Dart Install
The first step in learning any programming language is to set up a usable development environment locally.
This chapter will guide you through installing Dart SDK, configuring an editor, and running your first Dart program.
### Online Experience
If you just want to quickly experience Dart without installing anything locally, **DartPad** is the most convenient choice.
DartPad is an online editor provided by Dart. No registration is required - just open your browser to write and run code.
**Visit**: [https://dartpad.dev](https://dartpad.dev/)
!(#)
### Main Features of DartPad
* Write and run Dart code online, view output in real-time
* Built-in multiple sample programs, suitable for quick start
* Support sharing code links, convenient for collaboration and asking questions
* Support Flutter code preview (can run simple Flutter interfaces in browser)
* * *
## Install Dart SDK
Dart SDK contains all the tools needed to compile, run, and debug Dart programs.
Choose the appropriate installation method based on your operating system.
### macOS Installation
If you are using macOS, it is recommended to install via Homebrew:
$ brew tap dart-lang/dart $ brew install dart
After installation, verify the version:
$ dart --version Dart SDK version: 3.5.0 (stable)
### Windows Installation
Windows users can install via the Chocolatey package manager:
C:> choco install dart-sdk
Or visit [dart.dev/get-dart](https://dart.dev/get-dart) directly to download the installer, double-click to run the installation wizard.
### Linux Installation
Debian/Ubuntu systems can install via 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 dart
### Verify Installation
Regardless of which system you use, after installation you can verify that the SDK is working properly with the following commands:
$ dart --version $ dart --help
If you can see the version number and help information, the installation was successful.
* * *
## Using DartPad Online Editor
If you don't want to install any software for now, DartPad is the fastest way to get started.
DartPad is an online Dart editor provided by Google. No registration is required - just open and use it.
Visit: [https://dartpad.dev](https://dartpad.dev/)
Features of DartPad:
| Feature | Description |
| --- | --- |
| Zero Configuration | Open browser to write and run Dart code |
| Flutter Support | Can switch to Flutter mode to write examples with UI |
| Code Sharing | Generate links to share your code snippets |
| Syntax Highlighting | Built-in Dart syntax highlighting and code completion |
| Version Selection | Support choosing different Dart/Flutter versions |
> DartPad is very suitable for quickly verifying syntax and sharing code snippets. However, for complete project development, it is still recommended to configure a local IDE environment.
* * *
## Configure VS Code
VS Code is currently the most popular Dart development editor. Combined with the official plugin, it provides an excellent development experience.
### Installation Steps
Step 1, make sure VS Code is installed (download from [code.visualstudio.com](https://code.visualstudio.com/)).
Step 2, open VS Code and go to the Extensions store (shortcut `Cmd+Shift+X` or `Ctrl+Shift+X`).
Step 3, search for and install the Dart extension (publisher: Dart Code).
!(#)
> When installing the Dart extension, the Flutter extension will be installed automatically (if Flutter SDK is detected). If you plan to learn Flutter later, it is recommended to also install the Flutter extension.
### Verify Configuration
After installation, create a new file in VS Code and name it `hello.dart`.
Enter the following code. If you see syntax highlighting and code hints, the configuration is successful.
## Example
void main(){
print('Hello, TUTORIAL!');
}
### Run Code
There are three ways to run Dart code in VS Code:
| Method | Operation |
| --- | --- |
| Right-click Menu | Right-click in editor β Run Without Debugging |
| Shortcut | `Ctrl+F5` (Windows) or `Cmd+F5` (Mac) |
| Terminal Command | Open terminal and enter `dart run hello.dart` |
$ dart run hello.dart Hello, TUTORIAL!
### Other IDE Options
| IDE | Plugin Name | Applicable Scenario |
| --- | --- | --- |
| IntelliJ IDEA | Dart Plugin | Preferred for Java/Kotlin developers |
| Android Studio | Built-in Support | Flutter mobile development |
| VS Code | Dart Extension | General development, lightweight and fast |
* * *
## Dart Project Structure Overview
In addition to running single files, Dart also supports standardized project structure.
You can quickly create a Dart project skeleton using the dart create command:
$ dart create my_first_app
The generated directory structure is as follows:
my_first_app/βββ bin/β βββ my_first_app.dart # Program entry fileβββ lib/β βββ my_first_app.dart # Library code (reusable)βββ test/β βββ my_first_app_test.dart # Test fileβββ pubspec.yaml # Project configuration file (dependency management)βββ analysis_options.yaml # Static analysis rulesβββ README.md
Description of each directory's purpose:
| Directory/File | Purpose |
| --- | --- |
| bin/ | Stores executable program entry files |
| lib/ | Stores library code that can be referenced by other projects |
| test/ | Stores unit test files |
| pubspec.yaml | Project metadata and dependency declarations |
| analysis_options.yaml | Configure code static analysis rules |
Enter the project directory and run the project:
$ cd my_first_app $ dart run Hello world: my_first_app!
> For the stage of learning basic syntax, we mainly use single-file mode. When you start writing your own small projects, use dart create to create a standard project structure.
YouTip