Cyberithub

How to Install Dart SDK on Ubuntu 20.04 LTS (Focal Fossa)

Advertisements

In this article, I will take you through the steps to install Dart SDK on Ubuntu 20.04 LTS (Focal Fossa). Dart is a free and open source, client-optimized, object-oriented, general purpose programming language. It was developed by Google and launched in the year 2011. It is designed for developing faster applications that can run on any platform. Dart is extensively used with Flutter to build mobile apps for both Android and iOS. Dart provides the language and runtimes that power Flutter apps, but Dart also supports many core developer tasks like formatting, analyzing, and testing code.

 

Important Features

  • It is type safe.
  • Easy to Learn.
  • Optimized for designing user interfaces.
  • It is very flexible in use.
  • It uses static type checking.
  • It offers sound null safety.
  • It uses hot reload to see the changes instantly in the app.
  • Dart AOT compiled app launches with consistent, short startup time.
  • Dart Web enables running Dart code on web platforms.
  • Managed Memory Model where unused memory are reclaimed back by Garbage Collector(GC).
  • It supports mixin-based inheritance.

How to Install Dart SDK on Ubuntu 20.04 LTS (Focal Fossa)

How to Install Dart SDK on Ubuntu 20.04 LTS (Focal Fossa)

Also Read: How to Install Gparted on Ubuntu 20.04 LTS (Focal Fossa)

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get utility available in your Server.

d) You should have curl or wget utility available in your Server.

 

Step 2: Update Your Server

Let's start the steps to install Dart SDK on Ubuntu 20.04 LTS by first updating and upgrading the installed packages in the system by using sudo apt update && sudo apt upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease
Hit:5 https://repo.nordvpn.com//deb/nordvpn/debian stable InRelease
Hit:6 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:7 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:8 http://ppa.launchpad.net/wireshark-dev/stable/ubuntu focal InRelease
Hit:9 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:10 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:11 https://apt.boltops.com stable InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://apt.boltops.com stable InRelease' doesn't support architecture 'i386'
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
gparted-common
Use 'sudo apt autoremove' to remove it.
Try Ubuntu Pro beta with a free personal subscription on up to 5 machines.
Learn more at https://ubuntu.com/pro
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

 

Step 3: Install apt-transport-https

In the next step, you need to install apt-transport-https package if not already installed to secure the use of repositories over HTTP Secure Protocol(HTTPS). To install, you just need to use sudo apt-get install apt-transport-https command as shown below.

cyberithub@ubuntu:~$ sudo apt-get install apt-transport-https
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
apt-transport-https
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/1,704 B of archives.
After this operation, 162 kB of additional disk space will be used.
Selecting previously unselected package apt-transport-https.
(Reading database ... 270844 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_2.0.9_all.deb ...
Unpacking apt-transport-https (2.0.9) ...
Setting up apt-transport-https (2.0.9) ...

 

Step 4: Install Dart SDK

There are multiple ways to install dart sdk on Ubuntu 20.04 LTS Systems. Here we will see two most often used methods.

a) Using apt-get

First you need to download the GPG Key from official website using wget utility as shown below.

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

After downloading the key, you need to add the repo from where dart package will be downloaded using below echo command.

cyberithub@ubuntu:~$ 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
deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main

Update the package cache using sudo apt-get update command. This will update the information about the newly added repo to the System.

cyberithub@ubuntu:~$ sudo apt-get update
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:6 https://repo.nordvpn.com//deb/nordvpn/debian stable InRelease
Hit:7 http://security.ubuntu.com/ubuntu focal-security InRelease
Ign:8 https://storage.googleapis.com/download.dartlang.org/linux/debian stable InRelease
Hit:9 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:10 http://ppa.launchpad.net/wireshark-dev/stable/ubuntu focal InRelease
Hit:11 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
Get:12 https://storage.googleapis.com/download.dartlang.org/linux/debian stable Release [944 B]
Get:13 https://storage.googleapis.com/download.dartlang.org/linux/debian stable Release.gpg [819 B]
Hit:14 https://apt.boltops.com stable InRelease
Get:15 https://storage.googleapis.com/download.dartlang.org/linux/debian stable/main amd64 Packages [6,846 B]
Fetched 8,609 B in 2s (4,941 B/s)
Reading package lists... Done

Then install Dart SDK package from the newly added repo using sudo apt-get install dart command as shown below. This will download and install the package along with all its dependencies.

cyberithub@ubuntu:~$ sudo apt-get install dart
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
dart
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 126 MB of archives.
After this operation, 526 MB of additional disk space will be used.
Get:1 https://storage.googleapis.com/download.dartlang.org/linux/debian stable/main amd64 dart amd64 2.18.4-1 [126 MB]
Fetched 126 MB in 25s (5,080 kB/s)
Selecting previously unselected package dart.
(Reading database ... 270848 files and directories currently installed.)
Preparing to unpack .../dart_2.18.4-1_amd64.deb ...
Unpacking dart (2.18.4-1) ...
Setting up dart (2.18.4-1) ...

b) Using Debian Package

First you need to download the latest available Debian package from official website using any file transfer utility like wget or curl as shown below.

cyberithub@ubuntu:~$ wget https://storage.googleapis.com/dart-archive/channels/stable/release/latest/linux_packages/dart_2.18.4-1_amd64.deb
--2022-11-06 14:17:43-- https://storage.googleapis.com/dart-archive/channels/stable/release/latest/linux_packages/dart_2.18.4-1_amd64.deb
Resolving storage.googleapis.com (storage.googleapis.com)... 142.250.195.176, 142.250.195.208, 142.250.195.240, ...
Connecting to storage.googleapis.com (storage.googleapis.com)|142.250.195.176|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 126482784 (121M) [application/x-debian-package]
Saving to: ‘dart_2.18.4-1_amd64.deb’

dart_2.18.4-1_amd64.deb 100%[============================================================================>] 120.62M 5.82MB/s in 24s

2022-11-06 14:18:09 (5.09 MB/s) - ‘dart_2.18.4-1_amd64.deb’ saved [126482784/126482784]

Then Install Dart Package by using sudo dpkg -i dart_2.18.4-1_amd64.deb command as shown below.

cyberithub@ubuntu:~$ sudo dpkg -i dart_2.18.4-1_amd64.deb
Selecting previously unselected package dart.
(Reading database ... 270848 files and directories currently installed.)
Preparing to unpack dart_2.18.4-1_amd64.deb ...
Unpacking dart (2.18.4-1) ...
Setting up dart (2.18.4-1) ...

 

Step 5: Verify Installation

You can verify all the installed files by using dpkg -L dart command as shown below.

cyberithub@ubuntu:~$ dpkg -L dart
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/dart
/usr/share/doc/dart/copyright
/usr/share/doc/dart/changelog.Debian.gz
/usr/lib
/usr/lib/dart
/usr/lib/dart/lib
/usr/lib/dart/lib/web_sql
/usr/lib/dart/lib/web_sql/dart2js
/usr/lib/dart/lib/web_sql/dart2js/web_sql_dart2js.dart
/usr/lib/dart/lib/typed_data
/usr/lib/dart/lib/typed_data/unmodifiable_typed_data.dart
/usr/lib/dart/lib/typed_data/typed_data.dart
/usr/lib/dart/lib/typed_data/typed_data_sources.gni
/usr/lib/dart/lib/js_util
/usr/lib/dart/lib/js_util/js_util.dart
/usr/lib/dart/lib/js_util/js_util_sources.gni
/usr/lib/dart/lib/js_util/js_util_wasm.dart
................................................

 

Step 6: Check Version

To check the currently installed version, you need to use dart --version command as shown below.

cyberithub@ubuntu:~$ dart --version
Dart SDK version: 2.18.4 (stable) (Unknown timestamp) on "linux_x64"

 

Step 7: Writing Your First Program

Now that Dart SDK is successfully installed in the System, it is time to write your first dart program. Here we are writing a simple program to display "Hi, This is from CyberITHub !!" on the output using print statement.

cyberithub@ubuntu:~$ nano hello.dart
void main(){
print("Hi, This is from CyberITHub !!");
}

Output

cyberithub@ubuntu:~$ dart hello.dart
Hi, This is from CyberITHub !!

 

Step 8: Uninstall Dart SDK

Once you are done using Dart programming language, you can choose to uninstall it from your System by using sudo apt remove dart command as shown below.

cyberithub@ubuntu:~$ sudo apt remove dart
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
dart
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 526 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 271866 files and directories currently installed.)
Removing dart (2.18.4-1) ...

1 thought on “How to Install Dart SDK on Ubuntu 20.04 LTS (Focal Fossa)”

  1. Thanks a lot for this. This resource saved me a lot of time because of I've been battling with the installation since yesterday.

    Reply

Leave a Comment