Are you working on how to install Flutter and get Google’s framework running on Linux? Don’t worry, we’ve got you covered with this guide.
Flutter: The Basics
It is a Software Development Kit (SDK) used to develop cross-platform apps like Android, iOS, Linux, macOS, Windows, and even browsers. Flutter was first released in 2017 and then been actively used by and adopted by the developer community because of its multiplatform nature.
- Dart platform
- Flutter engine
- Design-specific widgets
- Flutter Development Tools
Flutter is based on a central idea called Widgets. These widgets can also be combined to form the entire UI. And they also define basic components like buttons, menus, navbar, font, color, padding, etc. Flutter does not use OEM widgets but provides its own that look native to Android or iOS apps.
These widgets are then compiled into their native target platform components.
Some benefits of Flutter are:
- A single codebase saves time and money
- It boasts excellent performance
- Development is also fast
- Has cross-platform compatibility
- Is open source
- Linux (64-bit OS)
- Free disk space, more than 600 MB excluding IDE/tools
- Some command tools required are
zip. These tools are also available by default in most Linux OS.
- Some libraries are
Installing Flutter With Snap
The first thing to install Flutter on Linux is to install Snap. To check if you have Snap installed or not, you can type the following command into the terminal:
And if it’s already installed, you should see output like this one:
If not, you have to type the following command to install it:
$ sudo apt install snapd
With everything set, you can now install Flutter on Linux with the following command:
$sudo snap install flutter --classic
Install Flutter on Linux manually
snapd is not installed, you can also alternatively install it with the following steps.
Download Flutter SDK
You can download Flutter SDK here. And also remember to download the latest stable release.
Extract the FIle
Extract the downloaded file in the location of your choice with the following command:
$ cd ~/dev
$ tar xd ~/Downloads/flutter_linux3.0.5-stable.tar.xz
Or you can directly clone the git repo from here using the following command:
$ git clone https://github.com/flutter/flutter.git
Now, you have to set the path variable for the current terminal (temporarily) like this:
$ export PATH=”$PATH: `pwd`/flutter/bin”
To permanently add a path, run the following command:
$ export PATH="$PATH:[PATH_OF_FLUTTER_GIT_DIRECTORY]/bin"
Either way, now you can verify with the following command:
$ which flutter
Output may look like this:
Configuring with flutter doctor
Flutter provides an automatic configuring tool to check if all dependencies are installed or not. The following command will configure all dependencies.
$ flutter doctor -v
And the output should look like this:
And with that, you are all set with flutter. However, you can see there that Android Studio and Java are not configured. And these components are essential for you to run the Android apps you developed. You can consider them as IDE.
Install and Configure Java
To run and use Android Studio, you need to have a Java Development Kit, which provides JRE. JRE is a java run time environment that provides a place for java programs to run after compilation.
To install the latest java stable version (V8), run the following commands:
$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk
Now, we have to set the environment variable for
$JAVA_HOME. Doing this will also allow the local Java apps to run.
You have to provide a path without including the /bin directory (for us, it’s
/usr/lib/jvm/java-8-openjdk-amd64). For example:
To set JAVA_HOME env var for the current user run the following command:
$ echo "JAVA_HOME=\"$JAVA_HOME\"" >> ~/.bashrc
Now to add binaries to your path, input:
$ echo 'export PATH=$PATH:$JAVA_HOME/bin' >> .zshrc
Verify everything is correct by typing in:
$ source ~/.bashrc && echo $JAVA_HOME
Now that everything is done, we can move forward to installing Android Studio and run the Flutter app in it.
Install and Configure Android Studio
First of all, download Android Studio from here.
Now open Android Studio using GUI or like this:
$ bash /usr/local/android-studio/bin/studio.sh
Either way, the install wizard will pop up.
To add flutter, we have to click on “Plugins”
Search for the official published plugin named “Flutter” by flutter.dev
You will be asked to install the dart plugin too. Flutter is based on dart programming language, so click “OK” and restart android studio.
Now, you will be prompted by the project configuration tab. Provide the project’s name and other info, and point the “Flutter SDK” to the location where Flutter is installed on your device.
Now, accept Android licenses and provide ownership to avoid build errors in the future with this command.
$ flutter doctor --android-licenses
$ sudo chown -R $USER:$USER /home/$USER/snap/flutter
And with that, you are all set to run Flutter on Android Studio.
In this guide, we’ve discussed what Google’s open-source framework is about, and how it can be installed on Linux. Moreover, we also detailed the basic steps to install and set up Java, along with Android Studio on the Linux system.
If this guide helped you, please share it.