How to Install Dart on Ubuntu with Hello World Code


Dart

This tutorial will guide you through step by step procedure to install Dart on Ubuntu, covering two installation methods (APT and Debian package), verifying the installation, creating a simple Dart program, and the uninstallation process, with easy-to-follow steps for beginners.

Dart is a modern, open-source programming language developed by Google, known for its efficiency in building high-quality web and mobile applications. It's designed to be easy to learn and provides a powerful framework for frontend development. Dart's syntax is clear and concise, making it an excellent choice for both beginners and experienced developers. A key feature of Dart is its ability to compile into native code, which enhances performance for mobile apps. It's famously used in conjunction with Flutter, Google's UI toolkit, for crafting natively compiled applications for mobile, web, and desktop from a single codebase. Dart's robust standard library, strong typing, and object-oriented features enable developers to build sophisticated applications efficiently.

 

1. Install Dart using APT Package Manager

This method is ideal if you prefer a more automated approach to manage software installations and updates. It's especially useful for those who regularly update their system and want Dart to be updated alongside other system packages.

 

1.1 Open the Terminal

Launch the Terminal on your Ubuntu system. You can do this by pressing `Ctrl + Alt + T` or searching for "Terminal" in your application menu.

 

1.2 Update System Repositories

First, update your system's package list to ensure it includes the latest versions of packages and their dependencies. This command needs to be run with sudo privilege:

sudo apt update -y
How to Install Dart on Ubuntu with Hello World Code

 

1.3 Download the GPG Key

Add the Google GPG key to your system to ensure the authenticity of the software package using wget command:

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

 

1.4 Add Dart Repository

Include the Dart SDK repository to your system's repository list.

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

 

1.5 Update Package List Again

Update the package list again to include the newly added Dart repository.

sudo apt update -y
How to Install Dart on Ubuntu with Hello World Code

 

1.6 Install Dart

Now, install Dart using the APT package manager.

sudo apt install dart -y

 

1.7 Verify Installation

After installation, you can verify Dart by checking its version.

dart --version

Sample Output:

Dart SDK version: 3.2.5 (stable) (None) on "linux_x64"

 

2. Install Dart using Debian Package

This method is more suited for users who prefer to have more control over the installation process. It's a good choice if you want to install a specific version of Dart or if you're installing Dart on a system where you don't have root access or prefer not to add external repositories.

 

2.1 Download Dart Debian Package

Download the Dart SDK Debian package from the official Dart website using wget. You may re-visit the official website to get the latest available stable release:

wget https://storage.googleapis.com/dart-archive/channels/stable/release/latest/linux_packages/dart_3.2.5-1_amd64.deb

 

2.2 Install Dart Package

You can check if dart package is already installed or not and then plan to install the downloaded Dart package using dpkg command:

sudo dpkg -i dart_3.2.5-1_amd64.deb
How to Install Dart on Ubuntu with Hello World Code

 

2.3 Verify Installation

After installation, you can verify Dart by checking its version.

dart --version

Sample Output:

Dart SDK version: 3.2.5 (stable) (None) on "linux_x64"

 

3. Creating a Simple Dart Program

Creating a basic Dart program is a great way to test your Dart installation and get started with the language. Here's a simple guide on how to create a "Hello World" program in Dart:

 

3.1 Open a Text Editor

You can use any text editor of your choice (like VS Code, Sublime Text, or even a simple one like Notepad).

 

3.2 Write the Dart Code

Type the following Dart code into your text editor:

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

This code defines a main function, which is the entry point for many programming languages, including Dart. The print() function is used to output "Hello, World!" to the console.

 

3.3 Save the File

Save the file with a .dart extension, for example, hello_world.dart. This extension is used for Dart files.

 

3.4 Run the Program

  • Open a terminal or command prompt.
  • Navigate to the directory where your Dart file is saved.
  • Run the program by typing dart hello_world.dart and hitting enter.
  • You should see "Hello, World!" printed in the terminal, indicating that your program has run successfully.
How to Install Dart on Ubuntu with Hello World Code

This simple exercise will not only confirm your Dart installation but also give you a feel for Dart syntax and executing Dart programs. Once you're comfortable with this, you can start exploring more complex Dart programming concepts. For more detailed information and tutorials on Dart programming, you can visit the Dart Programming Language official guides.

 

4. Uninstalling Dart

To uninstall Dart from your Ubuntu system, including the removal of the GPG key, repository, and any user-level settings, you can remove and purge any dependent packages:

sudo apt purge --autoremove -y dart

Delete the GPG key that was added during the installation of Dart:

sudo rm /usr/share/keyrings/dart.gpg

Remove the Dart repository from your system's sources list:

sudo rm /etc/apt/sources.list.d/dart_stable.list

If Dart was configured for a specific user, you might also want to remove any local settings:

rm -rf ~/.dart

By following these steps, you should be able to completely uninstall Dart from your Ubuntu system. Note that these steps assume you installed Dart using the APT package manager or directly from a Debian package. If Dart was installed using another method, the uninstallation steps might be different.

 

5. Conclusion

This guide covered installing Dart on Ubuntu, highlighting its role in developing scalable applications. We explored two installation methods (APT and Debian package), crafted a basic "Hello World" program to test the setup, and detailed the uninstallation process. Concluding with Dart's significance in development, we emphasized its ease of use and efficiency, making it a top choice for cross-platform application creation. The simple installation process on Ubuntu enhances Dart's accessibility for developers.

 

Deepak Prasad

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!