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:
      brew tap dart-lang/dart brew install dart
    • Verify the installation by running:
      dart --version
  • 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):
      export PATH="$PATH:/usr/local/lib/dart/bin"
    • Source your configuration file with source ~/.zshrc or source ~/.bash_profile.
    • Verify the installation with dart --version.

3. Installing Dart SDK on Linux

  • Option 1: Install via APT (Debian/Ubuntu-based distributions)

    • Add the Dart repository:
      sudo apt update sudo apt install apt-transport-https sudo sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /usr/share/keyrings/dart-archive-keyring.gpg' sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/dart-archive-keyring.gpg] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main" > /etc/apt/sources.list.d/dart_stable.list'
    • Install the Dart SDK:
      sudo apt update sudo apt install dart
    • Verify the installation by running dart --version.
  • 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:
      export PATH="$PATH:/opt/dart-sdk/bin"
    • Verify the installation with dart --version.

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:
    void main() { print('Hello, Dart!'); }
  • In your terminal, navigate to the directory with hello.dart and run:
    dart run hello.dart
  • 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.