Flutter, an open-source mobile application development SDK created by Google is getting more attention from developers nowadays. Here we will see the steps to install Flutter on Ubuntu operating system.
Flutter is used to develop applications for Android and iOS, as well as being the primary method of creating applications for Google Fuchsia (the capability-based operating system currently being developed by Google).
The official Flutter documentation page explains the steps to install Flutter on Ubuntu or any other Linux based OS. But I faced some issues when following it and some of the steps are a little bit confusing.
So, this is the reason behind the making of this tutorial. If you are confident of setting up Flutter with official documentation, go ahead. Else follow the steps.
Install Flutter on Ubuntu
Let’s start the procedure to install Flutter on Ubuntu. This includes various steps such as,
- JDK installation
- Android studio setup
- Flutter SDK installation
- Creating a new Flutter project
- Running the project on our Android device
1. Install JDK
Usually, Native Android apps are built in Java. So the Java Development Kit(JDK) is required to develop Android apps even if we are using any frameworks.
The Java Development Kit (JDK) is a software development environment used for developing Java applications and applets.
It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (JavaDoc), and other tools needed in Java development.
JDK can be installed on our Ubuntu system with the below commands.
sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-get update sudo apt-get install openjdk-8-jdk
2. Install and Set Up Android Studio
To develop applications for each operating system, they provide an Integrated Development Environment(IDE).
Microsoft Visual Studio is n IDE for developing Windows applications and Xcode is the IDE for developing macOS and iOS applications. So, Android studio is the official IDE for developing Android applications.
Yes, we are going to develop apps using the Flutter framework with Dart language. But Android apps can only be built using Java. So, the duty of the Flutter framework is to simply convert the Dart code to Java code.
This Java code will reach the tools in Android studio and from there, the app will be made and run on any Virtual machine or mobile device.
2.1 Download Android Studio Bundle
Android studio needs to be installed for working with Flutter development. So we can easily download an Android Studio zip file using the official link below.
https://developer.android.com/studio/index.html
In my case, I got the zip file named android-studio-ide-173.4907809-linux.zip
2.2 Unzip the File
Now Unzip the file to /opt directory by running the command.
sudo unzip android-studio-ide-173.4907809-linux.zip -d /opt
2.3 Create a Desktop Icon
Create a new file androidstudio.desktop under applications directory using nano editor.
sudo nano ~/.local/share/applications/androidstudio.desktop
Just copy and paste the below code in it.
[Desktop Entry] Version=1.0 Type=Application Name=Android Studio Exec="/opt/android-studio/bin/studio.sh" %f Icon=/opt/android-studio/bin/studio.png Categories=Development;IDE; Terminal=false StartupNotify=true StartupWMClass=android-studio
Use the below keyboard shortcuts to save the file.
Ctrl + O (Write out)
Enter
Ctrl + x (exit)
2.4 Configure ANDROID_HOME Environment variable
Environment variables are global system variables accessible by all the processes running under our Operating System (OS).
Some development processes running on our system need to access the system variables, and we need to create environment variables for them.
So open .bash_profile
file using nano editor.
sudo nano $HOME/.bash_profile
Just copy and paste the below code in it.
export ANDROID_HOME=$HOME/Android/Sdk export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/platform-tools
Use the below keyboard shortcuts to save the file.
Ctrl + O (Write out)
Enter
Ctrl + x (exit)
2.5 Install Flutter Plugin on Android Studio
It’s an optional step to install the Flutter plugin on Android Studio. But it helps us if we are developing our Flutter project from Android Studio. This also installs the Dart plugin which is required for Flutter development. This can be done from Android Studio Welcome Window.
Goto, Configure -> Plugin
Now, Search of Flutter and Install. It requires a restart for Android Studio to activate this plugin.
3. Install and Set Up Flutter SDK
So the dependencies are almost set and now we need to install and setup Flutter SDK. To start creating Flutter projects, Flutter Software Development Kit(SDK) is necessary. This can be installed on our system with the below steps.
3.1 Download Flutter SDK
First, we have to download Flutter SDK from the official flutter website.
Download the tar.xz
file.
This will download the file flutter_linux_v1.9.1+hotfix.6-stable.tar.xz
to our system. The file name may be varied with the newest releases. You have to take care of it.
3.2 Extract the File
I am assuming that the downloaded file is on the Downloads directory of our system. Now we need to extract this compressed file using the terminal command below
tar xf ~/Downloads/flutter_linux_v1.9.1+hotfix.6-stable.tar.xz
3.3 Adding Flutter to Our System’s Path
Now we need to add the Flutter to our system’s path using the below command.
export PATH=`pwd`/flutter/bin:$PATH
source $HOME/.bash_profile
4. Accept the Licences
For userspace (non-kernel) software, Google/Android prefer Apache 2.0 (and similar licenses such as BSD and MIT) over other licenses such as the Lesser General Public License (LGPL).
Here’s why the purpose of Android is to promote openness in the mobile world, and they can’t predict or dictate all the uses for their software.
So, we need to accept some licenses to start development with Flutter. Just run the below command and accept all the licenses by pressing y
.
flutter doctor --android-licenses
5. Update the Path Permanently
We already added the Path variable before. But it only valid for the current terminal window. We have to run the below command to make it permanent.
export PATH=Downloads/flutter/bin:$PATH
6. Creating a New Application
Creating a new application on Flutter can be done with three methods. Using Android Studio plugin, VS code plugin, or using Terminal + Editor method. Here, I am going with the third method(Terminal + Editor).
flutter create awesome_project
7. Choosing the Code Editor
We can choose our own favorite code editor for editing our project. But in my case, I choose the Visual Studio Code(Because it directly supports the Flutter and Flutter plugin).
https://code.visualstudio.com/#alt-downloads
From the above link, we can download the VS code .deb file compatible with Ubuntu/Debian. This deb file can be installed with a double-click on Ubuntu.
8. Directing to Our Project Directory and Start Editing
After installing VS code, direct to our project folder.
cd awesome_project
Open our project using VS code by just typing the below command.
code .
From now onwards, we can use VS code Terminal instead of the native Ubuntu Terminal because we can use the Terminal without going out of our code editor.
(Go to View -> Integrated Terminal from VS code’s top menubar)
9. Running the App on Android Device
Now we can run the project on our Android phone. We can also run this app on an Emulator also. But here, I am opting for a real Android device.
For this, on our Android mobile phone device,
Go to Settings->About
we can see a Build Version or Build Number menu there. Continuously click the option until it enables the Developer options
Now, return to Settings. We can see the Developer options menu there. Enable it. Also, enable the USB debugging option in it.
Connect our mobile device with our Ubuntu system using the USB port. Type the below command to check whether our mobile device is connected or not.
flutter devices
If it is connected, execute flutter run to run this app.
flutter run
This will install and open the newly created Flutter app on our connected Android device. I have added a screenshot of this view.
Summary
So, here in this article, we learned the steps to install Flutter on an Ubuntu operating system. All screenshots and commands are specified in this guide.
thanks for this you made my day..;)
Visual studio code gives me the error flutter not found but in terminal, it detects the flutter.i am on ubuntu 14.04 LTS
Thank you very much…..
While unzipping the file , you used different zip file name ..Its not same as you get and when I am unzipping my zipped file with same name then I m getting cannot find or open the file
Sorry for the mistake I made. I just corrected it. But you have to change the file name with the one that you downloaded.
Where the /opt directory has been created. is it on Desktop? Please explain bit more
On your terminal, type cd ~ and click enter (this will navigate you to the root folder). Now type cd opt and click enter. This will change the current directory to the opt directory.
This does not work at all: sudo unzip android-studio-ide-173.4907809-linux.zip -d /opt. It generates “cannot find or open android-studio-ide-173.4907809-linux.zip, android-studio-ide-173.4907809-linux.zip”
You can UnZip android studio manualling by right clicking on .zip file
Thanks SyamIaI
Great Tutorial!!!
Awesome time Saved
Thank you..!!
thank You very much
Made my day
Great Tutorial!
Thanks Man, It was really helpful.
Hi ! I follow the tutorial but when I run flutter doctor command I got an error : unable to find git in your PATH and I don’t know why.
I think you have to install Git to avoid this error.
1. Install Git
sudo apt-get install git
2. run
flutter doctor
commandDoesn’t work. You wasted my time!
Sorry for the inconvenience. A lot of people got the result using this guide and they also gave me positive comments.
Please share the error you are getting and I will surely help you in fixing it.
thanks a lot , after searching lots of things in youtube and google i got result from this blog Thanks 🙂
Thank you so much……I wasted my 10 hours in youtube google StackOverflow and flutter community..but no one told me to setup android studio path and accept the licence..finally, you saved me
Hi, your blog is really helpful to install the flutter on ubuntu. Great work.
It would be more helpful if you can add instructions on how to install flutter on windows and mac OS.
Thanks for your great work and amazing tutorial website.
If you can tell us how to install Xcode on Linux, that would be useful. This is not!
Really helpful
Just started my flutter course and this guide just made my day, oops i mean night.
would really love to know if you have guides on flutter android development.
And also django stack guidelines and environment set up using ubuntu.