Aug 13, 2024 7 min read

How to Install Dart on Debian 12

Install Dart on Debian 12 with our step-by-step tutorial. Dart is a Google-developed language, builds mobile, desktop, and web applications.

Install Dart on Debian 12
Install Dart on Debian 12
Table of Contents

Introduction

Before we begin talking about how to install Dart on Debian 12, let's briefly understand – What is Dart?

Dart is a programming language developed by Google, mainly used for building mobile, desktop, and web applications. It is an object-oriented language with a strong focus on simplicity and productivity. Dart boasts features like just-in-time compilation and hot reloading, making development faster and more efficient.

With its ability to run in multiple environments, Dart offers flexibility to developers. Its popularity has grown due to its clean syntax, fast performance, and extensive libraries, making it a preferred choice for app development.

In this tutorial, you will install Dart on Debian 12. We will also address a few FAQs on how to install Dart on Debian 12.

Advantages of Dart

  1. Versatile: Dart can be used to build mobile, desktop, and web applications, making it a flexible choice for developers.
  2. Productivity: Dart's simple and clean syntax, along with features like hot reloading, enable faster and more efficient development.
  3. Performance: Dart's just-in-time compilation and optimized execution deliver fast performance for applications.
  4. Strong libraries: Dart boasts a rich set of libraries that facilitate various tasks, reducing development time and effort.
  5. Cross-platform: Dart's ability to run on multiple platforms allows developers to create applications that work seamlessly across different devices, such as iOS, Android, Web, and desktop.

Import Dart APT Repository on Debian

Update Debian System Prior to Dart Installation

Installing Dart should begin with a Debian system update to ensure a smooth installation. This is an important step because it ensures compatibility and security by updating the system and any installed packages to the most recent versions. Use the terminal to enter the following command:

sudo apt update && sudo apt upgrade

This command uses apt update to update the package list, followed by apt upgrade to upgrade all installed packages to the most recent versions.

Install Necessary Packages for Dart

It is necessary to install packages that make it easier to add new repositories and manage their keys before importing Dart's repository. Tools for handling HTTPS connections, adding new software sources, and managing GPG keys are included in these packages. Install them by using:

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

Each of these packages contributes to the safe and dependable installation of software.

Import Dart GPG Key and APT Repository

Securely Importing the Dart GPG Key

The packages you are going to download are verified by the GPG key. Using wget, a command-line tool for downloading files from the internet, securely import the Dart GPG key:

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

This command ensures that any further downloads from the Dart repository are authenticated by retrieving the key and adding it to your system's keyring.

Configuring the Dart Repository

Stable Dart Repository (stable branch)

Most users should use the stable Dart repository, especially in production settings. It offers stability along with the newest features at a rate of about every three months.

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

Selecting stable releases guarantees that you are using versions of Dart that have been extensively tested and dependable.

Beta Dart Repository (testing branch)

Every month, new features are added to the beta repository, which provides an early look at them:

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

Developers can test their apps against future Dart releases or try out new features before they make it into the stable channel by using beta builds.

Dev Dart Repository (unstable branch)

For those who require the most recent updates on Dart developments, the dev repository is updated twice a week:

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

Although development builds offer the most recent updates, production use should not be undertaken due to their possible instability. They work best in development environments where it's essential to test new features and bug fixes.

Install Dart on Debian

Updating the APT Package Index

It is imperative to update the APT package index prior to installing Dart. By taking this step, you can be sure that your system is prepared to receive new software and that you have the most recent package listings.

If you want to update your Debian system, run the following command:

sudo apt update

By running this command, you can synchronize the local package database with your system's defined repositories and refresh it. Running this command before installing any new software is recommended to prevent potential conflicts with out-of-date packages.

Installing Dart

After updating the package index, run the following command to install Dart on your Debian system:

sudo apt install dart

Using this command, the Dart package is installed from the Debian repositories. The Dart SDK, a collection of resources and libraries necessary for Dart development, is part of the installation. The SDK offers a complete environment for developing Dart applications and contains the Dart VM, dart2js (a tool for converting Dart code to JavaScript), and other essential development tools.

Confirm Dart Installation

Run the following command after the installation is finished to verify the version you installed and its success:

dart --version
Dart version output in Debian terminal

Create a Test Application with Dart on Debian

Creating a Command-Line App

To start, create a command-line application using the console template and the dart create command:

dart create -t console my_dart_app

This command creates a basic Dart application with the following structure:

  • Main Dart Source File: Located at bin/my_dart_app.dart and has a main() function at the top level. This is the starting point for your application.
  • Additional Dart File: This file, which is imported by the my_dart_app.dart, is located under lib/my_dart_app.dart and contains the functionality of the app.
  • Pubspec File: Package dependencies and necessary versions are among the app's metadata that can be found in the pubspec.yaml file.

Note: To analyze the generated pubspec file and download required dependencies, dart create internally runs dart pub get. To fetch additional dependencies that you add later, run dart pub get again.

Dart create command in Debian terminal

Running the Application

Open the application's directory and use the Dart VM to run it:

cd my_dart_app
dart run

The default output, which is usually a "Hello world" message with a numerical value, should be displayed to you.

Dart Hello World program output in Debian

Customizing the App

Let's tweak your app a little bit. Change the lib/my_dart_app.dart calculation. For example, alter the numbers used or the arithmetic operation.

Here's an illustration of how to divide the initial value by two:

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

Relaunch the main entry point of the app after saving your changes:

dart run

Your changes should be reflected in the output, which will show the updated outcome.

Modified Dart Hello World program in Debian

Compiling for Production

The app has been running so far on the Dart virtual machine (VM), which is designed for quick development. Use AOT (Ahead-of-Time) compilation to compile your Dart code to optimized native machine code before putting it into production. This improves your application's overall performance and startup speed.

Assemble the software using:

dart compile exe bin/my_dart_app.dart

Launch the program that has been compiled and note how quickly and instantly it starts up:

time bin/my_dart_app.exe

The compiled application's efficiency will be demonstrated by the execution time metrics that are presented.

FAQs to Install Dart on Debian 12

How can I add the Dart repository to my Debian system?

You can add the Dart repository by downloading and importing the repository's GPG key, and then adding the repository itself to the package sources list.

How do I update the package lists on Debian 12?

To update the package lists on Debian 12, open a terminal and run the command: sudo apt update

Which package manager should I use to install Dart on Debian 12?

You can use the Advanced Packaging Tool (APT) package manager to install Dart on Debian 12.

Can I install specific versions of Dart on Debian 12?

Yes, you can install specific versions of Dart by specifying the version number during the installation process. 

Is Dart available for other operating systems?

Yes, Dart is available for various operating systems like Windows, macOS, and Linux, including Debian 12. You can find specific installation instructions for each OS on the official Dart website.

What are the prerequisites for installing Dart on Debian 12?

Before installing Dart on Debian 12, ensure that you have curl and other necessary dependencies installed. You can use the apt package manager to install these prerequisites.

Can I use Dart for both frontend and backend development on Debian 12?

Yes, Dart can be used for both frontend and backend development on Debian 12. It offers frameworks like Flutter for frontend and Shelf for backend development.

Conclusion

We hope this tutorial helped you understand how to install Dart on Debian 12.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.