Installing Dart Programming Language on Linux

Linux TLDR
Last Updated:
Reading time: 4 minutes

Dart, a prominent programming language, is developed and maintained by tech titan Google. Google’s Flutter leverages Dart as its language, empowering developers to develop cross-platform applications from a single codebase.

It aims to provide a productive and readable C-style syntax while offering features that make it easier for developers to build high-performance applications.

In this article, you will learn how to install Dart on Linux and configure Vim as an IDE for Dart, with some examples showcasing the usage.

Tutorial Details

DescriptionDart Programming Language
Difficulty LevelLow
Root or Sudo PrivilegesYes
OS CompatibilityDebian, Ubuntu, Linux Mint, etc.
Internet RequiredYes

How to Install Dart on Linux

Please note that Dart installation is currently supported on Debian and Ubuntu-based distributions only, with no official support for Red Hat, Fedora, or Arch-based distributions.

Dart support for Linux systems

You can use the Flutter snap package on unsupported distributions since Dart is included, but the decision is yours.

Now, Installing Dart in Debian or Ubuntu-based distributions is a breeze – just open your terminal and execute the following commands one after the other.

If you already have Flutter installed, there’s no need to follow the mentioned steps.

1. Begin by refreshing your system’s repository information to ensure it’s up-to-date, then proceed to upgrade any pending packages.

$ sudo apt update
$ sudo apt upgrade

2. Add the GPG key from Google.

$ wget -qO- | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg

3. Add the Dart SDK repository.

$ echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list

4. Finally, update your system repository information and install the latest version of Dart on your system.

$ sudo apt update
$ sudo apt install dart

Once the installation is finished, run the following command to ensure accessibility to Dart:

$ dart --version


Checking the Dart version

Disable Sending Usage Metrics and Crash Reports to Google

Dart is a Google product and may send anonymous usage metrics and crash reports to help improve its product and overall development experience.

While it has no impact on functionality, individuals prioritizing their privacy can easily disable anonymous analytics in Dart by setting the β€œ--disable-analytics” flag.

For Individual Commands

When running a Dart command, you can add the β€œ--disable-analytics” flag to disable the analytics for that specific command. For example:

$ dart --disable-analytics your_script.dart

For All Commands

To disable analytics for all Dart commands, you can set the environment variables in your shell configuration files (let’s say β€œ~/.bashrcβ€œ).

1. Open your shell configuration file using your choice of text editor:

$ vim ~/.bashrc

2. Add the following line at the end of the file:

alias dart="dart --disable-analytics"

3. Save the file, close it, and then refresh your shell configuration.

$ source ~/.bashrc

Now, let’s delve into practical examples showcasing the use of Dart.

How to Use Dart on Linux

Assuming you’ve already completed the earlier steps and installed the latest Dart version on your system. Once you have the SDK installed, you can use the β€œdart” command-line tool to run your Dart programs.

Here’s how you can do it:

1. Create a file using your preferred text editor, then copy the following content into it:

void main() {
  print('Hello World!');

2. Save the file with the β€œ.dart” extension as the β€œdart_exp1.dart” filename in a suitable location.

3. Open your terminal and navigate to the directory where your Dart program is located. To run the program, enter the β€œdart” command and the filename of your Dart file (assuming β€œdart_exp1.dartβ€œ).

$ dart dart_exp1.dart


Running the first Dart program on Linux

Congratulations on running your first Dart program on Linux!

Now, you can go further and start writing complex Dart programs that include multiple variables and data types.

For example, the following program will utilize multiple variables with different data types and then output them together using the β€œprint()” function.

void main() {
  // Variables and data types
  int age = 18;
  double height = 6.2;
  String name = 'Alex';
  bool isStudent = true;

  print('$name is $age years old, $height feet tall, and a student: $isStudent');


Running the second Dart program on Linux

Setting Up Vim as an IDE for Dart

Dart is great to use with modern IDEs, but if you are utilizing a command-line based text editor to develop Dart programs, let’s say VIM, you can install certain plugins that can enhance your development experience to the next level.

1. Prior to installing any VIM plugin, ensure that you have β€œvim-plug” installed. If not, execute the following command to install it:

#For Vim
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs

#For Neovim
$ sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs'

2. Add the following lines to your Vim configuration file (β€œ~/.vimrcβ€œ).

call plug#begin('~/.vim/plugged')

#Dart Plugins
Plug 'dart-lang/dart-vim-plugin'
Plug 'natebosch/vim-lsc'
Plug 'natebosch/vim-lsc-dart'

call plug#end()

3. Open Vim and run the following command to install the plugin:


Now, all the Dart syntax will be highlighted with beautiful color in Vim, as shown:

Dart syntax highlighting in Vim

To include line numbers for each line, insert the β€œset number” command in your β€œ~/.vimrc” file.

call plug#begin('~/.vim/plugged')

#Dart Plugins
Plug 'dart-lang/dart-vim-plugin'
Plug 'natebosch/vim-lsc'
Plug 'natebosch/vim-lsc-dart'

#Show Line Numbers
set number

call plug#end()

Save and close the file, and open your Dart program in Vim.

Showing the line numbers in Vim

To execute your Dart program within Vim, follow these steps: Open Vim, then replace β€œlocation” in the command below with your actual Dart program’s location and execute it.

:term dart /home/linuxtldr/dart_exp2.dart


Running the Dart program within Vim

Now, let’s end this article here.

Final Word

Note that Dart can also be installed via the Debian package provided by Dart itself. However, the steps to install Dart via the Debian package are intentionally skipped as they require more manual effort, and updating is quite troubling.

Apart from that, if you have any questions or queries related to this article, then feel free to tell us in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.