How to Install Dart on Debian 12, 11 or 10

This guide will cover how to install Dart on Debian 12, 11, or 10 Linux using the command-line terminal. It focuses on utilizing Dart’s APT repository for accessing the latest version and ensuring future updates.

Dart, a modern programming language developed by Google, is renowned for its versatility and efficiency, making it a top choice for developers and system administrators working on Debian-based servers. Dart’s streamlined syntax and robust feature set cater to a wide range of applications, from server-side to web and mobile development.

Here’s why Dart stands out:

  • Approachable and Strongly Typed: Dart’s appeal lies in its consistent and concise nature, complemented by modern language features like null safety and patterns. Its strong typing system ensures that developers can write clear, understandable code while minimizing errors.
  • Portable Across Platforms: Dart’s versatility is showcased in its ability to compile to various machine code types like ARM, x64, and RISC-V, covering a wide spectrum of devices, including mobile, desktop, and backend systems. For web development, it effortlessly compiles to JavaScript or WebAssembly.
  • Enhanced Productivity: Iterative changes are a breeze with Dart, thanks to its hot reload feature that reflects code modifications instantly in running apps. Dart’s DevTools further aid in diagnosing and resolving app issues efficiently.

Dart’s compiler technology is tailored for flexibility, catering to different platforms and development goals:

  • Dart Native: This includes a Dart VM for just-in-time (JIT) compilation and an ahead-of-time (AOT) compiler for generating machine code. It’s ideal for applications targeting various devices, including mobile, desktop, server, and more.
  • Dart Web: Focused on web development, Dart Web features a development time compiler (dartdevc) and a production time compiler (dart2js), ensuring optimal performance and efficiency across different stages of web application development.

The integration of Dart into Debian Linux servers empowers developers and sysadmins with a robust toolset, enhancing the development process and contributing to the efficient management of server-side applications. This guide delves into the technical aspects of installing Dart, bridging the gap between its powerful features and practical implementation on Debian 12, 11, or 10 Linux.

Import Dart APT Repository on Debian

Update Debian System Prior to Dart Installation

To ensure a smooth Dart installation, start by updating your Debian system. This step is crucial as it updates existing packages and the system to the latest versions, ensuring compatibility and security. Execute the following command in the terminal:

sudo apt update && sudo apt upgrade

This command first updates the package list (with apt update) and then upgrades all your installed packages to their latest versions (with apt upgrade).

Install Necessary Packages for Dart

Before importing Dart’s repository, it’s important to install packages that facilitate the addition of new repositories and the management of their keys. These packages include tools for handling HTTPS connections, managing GPG keys, and adding new software sources. Install them using:

sudo apt install lsb-release dirmngr software-properties-common apt-transport-https wget ca-certificates

Each of these packages plays a role in ensuring secure and reliable software installation.

Import Dart GPG Key and APT Repository

Securely Importing the Dart GPG Key

The GPG key authenticates the packages you’ll be downloading. Import the Dart GPG key securely using wget, a command-line utility for downloading files from the internet:

wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg

This command fetches the key and adds it to your system’s keyring, ensuring that all subsequent downloads from the Dart repository are verified for authenticity.

Configuring the Dart Repository

Stable Dart Repository (stable branch)

Most users should use the stable Dart repository, particularly in production environments. It updates approximately every three months, providing a balance between the latest features and stability:

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

Opting for stable releases ensures that you are working with thoroughly tested and reliable versions of Dart.

Beta Dart Repository (testing branch)

The beta repository receives monthly updates, offering a preview of upcoming features:

echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian testing main' | sudo tee /etc/apt/sources.list.d/dart_beta.list

Beta builds are ideal for developers who want to test their applications against upcoming Dart releases or experiment with new features before they hit the stable channel.

Dev Dart Repository (unstable branch)

The dev repository updates twice a week for those who need the absolute latest developments in Dart:

echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian unstable main' | sudo tee /etc/apt/sources.list.d/dart_dev.list

Dev builds provide the newest changes, but their potential instability makes them unsuitable for production use. They suit development environments best, where testing the latest features and bug fixes is critical.

Install Dart on Debian

Updating the APT Package Index

Before installing Dart, it’s essential to update the APT package index. This step ensures you have the latest package listings and your system is ready to receive new software.

Use the following command to update your Debian system:

sudo apt update

Executing this command refreshes the local package database, syncing it with the repositories defined in your system. It’s a best practice to run this command before installing any new software to avoid potential conflicts with outdated packages.

Install Dart on Debian via APT Command

Once the package index is updated, you can proceed to install Dart on your Debian system, using the following command:

sudo apt install dart

This command downloads and installs the Dart package from the Debian repositories. The installation includes the Dart SDK, which is a set of tools and libraries essential for Dart development. The SDK includes the Dart VM, dart2js (a tool for compiling Dart code to JavaScript), and other vital development tools, providing a comprehensive environment for building Dart applications.

Confirm Dart Installation

Once the installation is complete, run the following command to confirm the version you installed along with its success:

dart --version
Dart version output in Debian terminalPin
Dart version command output on Debian Linux

Create a Test Application with Dart on Debian

Creating a Command-Line App

Begin by using the dart create command with the console template to set up a command-line application:

dart create -t console my_dart_app

This command crafts a simple Dart application structured as follows:

  • Main Dart Source File: Located at bin/my_dart_app.dart, containing a top-level main() function. This is your application’s entry point.
  • Additional Dart File: Found under lib/my_dart_app.dart, this file houses the app’s functionality and is imported by the my_dart_app.dart file.
  • Pubspec File: The pubspec.yaml file includes metadata about the app, such as package dependencies and required versions.

Note: dart create internally executes dart pub get to analyze the generated pubspec file and download necessary dependencies. If you add more dependencies later, run dart pub get again to fetch them.

Dart create command in Debian terminalPin
Using Dart CLI to create a new app on Debian

Running the Application

Navigate to the app’s directory and run the application using the Dart VM:

cd my_dart_app
dart run

You should see the default output, typically a “Hello world” message with a numeric value.

Dart Hello World program output in DebianPin
Output of a simple Dart Hello World program in Debian

Customizing the App

Let’s make a small change to your app. Modify the calculation in lib/my_dart_app.dart. For instance, change the arithmetic operation or adjust the numbers used.

Here’s an example of dividing the original value by two:

int calculate() {
  return 6 * 7 ~/ 2;
}

After saving your changes, rerun the app’s main entry point:

dart run

The output should reflect your modifications, displaying a new result.

Modified Dart Hello World program in DebianPin
Running a customized Dart Hello World program in Debian

Compiling for Production

So far, you’ve run the app using the Dart VM, which is optimized for rapid development. For production, compile your Dart code to optimized native machine code using AOT (Ahead-of-Time) compilation. This step enhances the start-up speed and overall performance of your application.

Compile the program with:

dart compile exe bin/my_dart_app.dart

Run the compiled program and observe the instant start and swift execution:

time bin/my_dart_app.exe

The execution time metrics will be displayed, showing the efficiency of the compiled application.

Conclusion

In this guide, we walked through the steps to set up Dart on your Debian system, from updating the package index and installing Dart, to creating and customizing a basic command-line application. We also delved into compiling the application for production use, ensuring you’re ready to build more complex projects with confidence. Remember, the key to mastering Dart lies in experimentation and consistent practice. So, dive in, explore more features, and start building your next great application. Happy coding!

Leave a Comment


Your Mastodon Instance
Share to...