Installing Flutter and Android Studio in Debian and Ubuntu based Linux systems.

There are many ways to install Android Studio on Linux, but today we will be looking on the easiest method to get started with your app development using Flutter and Android Studio.

We will be using JetBrains Toolbox to install Android Studio. FIrstly, to install package.

The package you downloaded will be a tarball (compressed folder) consisting the JetBrains Toolbox executable file. Now, navigate to the directory where you download the package (using terminal or file explorer) and then extract the contents of the package.

If you are using a file explorer to view the package, then you can right click the package and select "Extract here" option. In the terminal, you can extract the contents of the file by running the following command:

tar -xzvf <package_name>.tar.gz

Replace the <package_name> with the actual name of the package. The contents of the file will be extracted into the current directory you are in. Navigate to the extracted package and then run the JetBrains Toolbox app. If you cannot run it in the first try, it may be because the file is not made executable by default. So you may need to run this command in order to be able to run the app:

chmod a+x <file_name>

Replace <file_name> with the actual name of the app binary you tried to run ( in this case JetBrains Toolbox app). After that, you can just open up your Application Drawer and find the JetBrains Toolbox app and run it.

A friendly reminder that JetBrains Toolbox is not the only source from where you can install it. I am just using it because it is the most convenient way rather than having to manually download a tarball of Android Studio.

Installing Android Studio

The app window will pop up and list some of the available tools you can install. Now choose Android Studio and click Install. After the installaton has finished, you can once again open up the Applicatioin Drawer and launch the Android Studio app.

You will be greeted by a installation window and if you have any saved configurations for Android Studio before, you can choose to launch it using the configurations you already have. If that is not the case, then you can just install it using the recommended setup.

After you finish installing the necessary components, go to Settings and select Plugins . There you want to install the Flutter plugin for Android Studio. You will also want to install the command line SDK tools for Android Studio. In order to do that, go to Settings > Languages and Frameworks > Android SDK page and then click the SDK Tools tab. If you scroll down a bit, you will see Android SDK Command Line Tools check its box and then click Apply or OK in the bottom right corner. SDK CLI Tools will be downloaded for you automatically. If you want to install a specific version of SDK or maybe any other SDK, then you can do it in this page as well.

Now, we are done with the Android Studio part. Let's move on to the Flutter part.

Flutter Installation

Default Installation (Tarball)

The flutter package can be installed via the official documentation website. All you have to do is download the tarball from the given link.

Extract the tarball to your target directory where you want to install the flutter binary. You can do this by using the following command:

tar -xvf ~/Downloads/flutter_*.tar.xz -C ~/.local/

In the above command, we assume that the downloaded tarball is in the ~/Downloads directory and the path after -C option is the destination where your extracted files will reside (in my case: ~/.local/). You can modify the destination directory as you want, but you need to remember where you have extracted the files (since you’re going to need to add it to PATH manually).

Since your system will not know where the flutter executable file is, we will need to add this to our PATH. Run the following command:

echo 'export PATH="~/.local/flutter/bin:$PATH"' >> ~/.zshrc

The above command appends the line export PATH=”~/.local/flutter/bin:$PATH”’ in our .zshrc file, because I am using ZSH. You can check which shell you are using with the following command:

echo $SHELL

If you are not using ZSH, then you may append the above line to your .bashrc , .bash_profile or .profile or whatever shell you are using.

After you have successfully added it to your path, then you need to restart all your terminal sessions and run flutter doctor to confirm your installation.

Install using asdf version manager

Besides, the above procedure is not the only way to install Flutter. Here, we will be looking at how to install it using asdf version manager. Installing Flutter using asdf is more flexiblle in my opinions just because you can install a specific version of Flutter easily using a simple command.

If you have installed it as per the official documentation, you need to manually search for a tarball of the exact flutter version you want to upgrade or downgrade to. Then, you need to manually download the tarball and extract it again. What if I told you there is an easier way:

What is asdf?

asdf is an open-source multiple tool version manager, it supports almost all major development tools and that is why we chose this version manager. In our case (for Android development), we really only need to manage versions for flutter (and dart). If you want to see all the tools (or packages) that asdf can manage, then take a look at the list of plugins here.

Some popular tools you can manage with asdf includes nodejs, fzf, Go, Helm, Lua, PHP, etc. We use this becasue even if you want to work on some other projects other than mobile applications, then this version manager will be able to handle this easily.

Using asdf

To add the Flutter plugin to asdf, we need to run the following command:

asdf plugin-add flutter

To list all the available versions of Flutter, run this:

asdf list all flutter

To install (or uninstalll) a specific version of Flutter, run this command:

# Install a specific version
asdf install flutter <VERSION_NUMBER>

# Example
asdf install flutter 2.5.2-stable

# Uninstall
asdf uninstall flutter <VERSION_NUMBER>

Global vs Local Flutter version

You can define a global and local version of Flutter depending on what projects you are working on. The global version is the default version your system is going to use on a general basis. The local version of Flutter is only for the current directory or project you are working on.

# Define a Global Flutter version
asdf global flutter <VERSION_NUMBER>

# Define a Local Flutter version
asdf local flutter <VERSION_NUMBER>

Exporting to $PATH

In order to have access to the flutter binary you have currently selected, you need to export asdf flutter to $PATH. Since I am using ZSH, I will add the following lines to my .zshrc file:

export PATH="$(asdf where flutter)/bin":"$PATH"

If you are using bash or any other type of shell, then you can add this line to .bashrc, .bash_profile or another equivalent environment config file. After this, you need to restart any terminal sessions you have opened.

You can confirm that you can access the flutter binary by running flutter —version to display the current flutter version. If this results to an unknown command or some error, check your asdf flutter plugin installation or reinstall the plugin.

Dart as well?

Dart is included by Flutter by default with the asdf flutter plugin. But in some rare cases, you may need to manually install a specific Dart version. YOu can do so by running the following command:

asdf plugin-add dart https://github.com/patoconnor43/asdf-dart.git

It is recommended that you add the git url at the end if possible, like I did above..

Like Flutter, you can install specific version of Dart by the following commands:

# Install Dart
asdf install dart <VERSION_NUMBER>

# Uninstall Dart
asdf uninstall dart <VERSION_NUMBER>

Conclusion

Now this is one of the most convenient way to install Flutter (and Dart) on your Linux system. But keep in mind that this is not the only way to install these packages. If you are more comfortable manually installing a binary everytime you want to switch a version, that is okay too. We all have our personal preferences. Like I said, I chose asdf version manager just because it can manage versions for a lot of tools, so it is convenient if you are working with other programming languages as well.

Thank you for reading and I hope you find this article useful for your project setup. Happy coding..!

0
Subscribe to my newsletter

Read articles from Lalrinfela Pachuau directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Lalrinfela Pachuau
Lalrinfela Pachuau

System Administrator for Lailen Consulting Pvt. Ltd