Get started: command-line and server apps

    With you can experiment with the Dart language andAPIs, no download necessary.

    For example, here’s an embedded DartPad that lets you play with the code for asmall Hello World program. Click Run to run the app; output appears in theconsole view. Try editing the source code — perhaps you’d like to change thegreeting to use another language.

    Note: If you see an empty box instead of code, go to theDartPad troubleshooting page.

    More information:

    2. Install Dart

    Once you’re ready to move beyond DartPad and develop real apps,you need the Dart SDK.

    • Windows
    • Linux
    • Mac

    Use Chocolatey to install a stable release of the Dart SDK:

    You can use Aptitude to install the Dart SDK on Linux.

    • Perform the following one-time setup:
    1. $ sudo apt-get install apt-transport-https
    2. $ sudo sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
    3. $ sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
    • Install the Dart SDK:
    1. $ sudo apt-get update
    2. $ sudo apt-get install dart

    With installing Dart is easy.

    3. Get more command-line developer tools

    Install stagehand, which gives you templates for creating Dart apps:

    Note that although these instructions feature the command line,many IDEs support Dart development.Those IDEs use Stagehand behind the scenes when you create new Dart projects.

    More information:

    Create a command-line app:

    1. $ mkdir cli
    2. $ cd cli
    3. $ stagehand console-full

    These commands create a small Dart app that has the following:

    • A main Dart source file, bin/main.dart, that contains a top-levelmain() function. This is the entrypoint for your app.
    • An additional Dart file, lib/cli.dart, that contains the functionality ofthe app and is imported by the main.dart file.
    • A pubspec file, pubspec.yaml, that contains the app’s metadata, includinginformation about which the app depends onand which versions of those packages are required.

    5. Get the app’s dependencies

    Use the command to get the packagesthat the app depends on:

    1. $ pub get

    6. Run the app

    To run the app from the command line, use the Dart VM by running the command:

    If you wish run the app with debugging support, seeDevTools.

    • Edit lib/cli.dart to calculate a different result. For example, divide theprevious value by two (for details about ~/, see ):
    1. int calculate() {
    2. return 6 * 7 ~/ 2;
    • Save your changes.

    • Rerun the main entrypoint of your app:

    1. $ dart bin/main.dart
    2. Hello world: 21!

    More information:Write command-line apps

    8. Compile for production

    The steps above used the Dart VM (dart) to run the app. The Dart VM isoptimized for fast, incremental compilation to provide instant feedbackduring development. Now that your small app is done,it’s time to AOT compile your Dart code to optimized native machine code.

    Use the dart2native tool to AOT compile the program to machine code:

    Notice how the compiled program starts instantly, completing quickly:

    What next?

    Check out these resources:

    If you get stuck, find help at Community and support.