Setting Up Dart SDK
Setting up the Dart SDK is the first step toward developing applications using the Dart language. The Dart SDK provides tools and libraries for writing, compiling, and running Dart code. Here’s a step-by-step guide on setting up the Dart SDK on different operating systems:
1. Installing Dart SDK on Windows
- Step 1: Go to the official Dart website.
- Step 2: Under the Windows section, click on the download link for the Dart SDK.
- Step 3: Extract the downloaded
.zip
file to a location of your choice. - Step 4: Add Dart to your system path:
- Open Settings > System > About > Advanced system settings.
- In the System Properties dialog, click on Environment Variables.
- Under System variables, find Path, click Edit, and add the path to the
bin
directory of the extracted Dart SDK (e.g.,C:\dart-sdk\bin
).
- Step 5: Open a command prompt, type
dart --version
, and press Enter to check the installation.
2. Installing Dart SDK on macOS
Option 1: Install via Homebrew (Recommended)
- If you have Homebrew installed, open the terminal and run:
- Verify the installation by running:
- If you have Homebrew installed, open the terminal and run:
Option 2: Manual Installation
- Download the
.zip
file from dart.dev under the macOS section. - Extract the file and move it to
/usr/local/lib
or another directory of your choice. - Add Dart to your path by editing your shell’s configuration file (e.g.,
.bash_profile
or.zshrc
): - Source your configuration file with
source ~/.zshrc
orsource ~/.bash_profile
. - Verify the installation with
dart --version
.
- Download the
3. Installing Dart SDK on Linux
Option 1: Install via APT (Debian/Ubuntu-based distributions)
- Add the Dart repository:
- Install the Dart SDK:
- Verify the installation by running
dart --version
.
- Add the Dart repository:
Option 2: Manual Installation
- Download the
.tar.gz
file from dart.dev under the Linux section. - Extract it to
/opt
or another preferred location. - Add Dart to your system’s path:
- Verify the installation with
dart --version
.
- Download the
4. Setting Up Dart in Visual Studio Code (VS Code) (Optional)
- After installing the Dart SDK, install VS Code if you haven’t already.
- Open VS Code and go to Extensions (left sidebar).
- Search for and install the Dart extension (by Dart Code).
- The extension should detect your Dart SDK automatically. You can now write, run, and debug Dart code within VS Code.
5. Running Your First Dart Program
- Create a new Dart file, e.g.,
hello.dart
. - Add the following code:
- In your terminal, navigate to the directory with
hello.dart
and run: - You should see the output
Hello, Dart!
printed to the terminal, confirming that Dart is correctly set up.
By following these steps, you’ll have the Dart SDK set up on your system, ready for development across platforms like mobile, web, and desktop using Dart and Flutter.