Dart is a programming language designed for the development of mobile, desktop, web, and server applications. It is an object-oriented, garbage-collected language that has syntax similar to the C programming language.
Dart can be compiled to either native code or JavaScript. It is developed and maintained by Google.
In this article, I will discuss how to install the Dart programming language in Ubuntu.
Prerequisites
You should have access to a user account with sudo privileges.
Installing Dart in Ubuntu
You can follow the instructions that are given below to install the Dart programming language on a Ubuntu system.
Before installing Dart make sure the local package repository is updated –
sudo apt update
sudo apt upgrade -y
Next, use the following command to install HTTPS support for apt –
sudo apt install apt-transport-https
Add Dart SDK repository
Import the GPG key by using –
sudo sh -c 'wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
Add the Dart SDK repository by using –
sudo sh -c 'wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
Installing Dart
Once the Dart SDK repository gets added to your system, use the given command to refresh the local package repository –
sudo apt update
Run the following command to install Dart on your system –
sudo apt install dart
Press y and then enter if it asks for your confirmation.
Setup environment variable
After installing Google Dart SDK add its bin directory to the PATH environment variable –
export PATH="$PATH:/usr/lib/dart/bin"
To change it to all the future terminal sessions use –
echo 'export PATH="$PATH:/usr/lib/dart/bin"' >> ~/.profile
Check Dart version
You can verify the Dart installation by checking the version installed on your system.
dart --version
This will display output as given in the image below.
Writing Hello World program in Dart
Open a text editor or an IDE with the Dart plugin installed and add the given code.
void main() { print('Hello, World!'); }
As you can see in the image below –
Save this code with .dart
extension and exit from the editor.
Now use the following command to execute this program –
dart hello.dart
You can see the output of this program in the image below.
For more usage of the Dart language, you can follow its official documentation.
Conclusion
You have successfully set up Google Dart on your Ubuntu system. Now if you have a query then write us in the comments below.