Table of Contents
In this article, we will go through the steps to install flutter on Ubuntu 20.04 LTS. Flutter is an open source framework from Google which is used to develop cross platform applications for Android, iOS, Mac, Windows and for other platforms. The reason why anyone chooses this framework because it completely transform the way application development happens. You can now build, test and develop amazing mobile, desktop, web and embedded apps from a single codebase.
How to Install Flutter on Ubuntu 20.04 LTS
Also Read: How to Install and Setup Firewall GUI on Rocky Linux 8
Step 1: Prerequisites
a) You should have a running Ubuntu 20.04 LTS
Server.
b) You should have sudo
or root
access to run privileged commands.
c) You should have snap
, apt
, wget
and tar
utility available in your Server.
Step 2: Update Your Server
You can update your System packages to the latest version by using apt update
command. If needed, you can also upgrade the required packages by using apt upgrade command.
root@cyberithub:~# apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Ign:4 http://ppa.launchpad.net/bitcoin/bitcoin/ubuntu focal InRelease
Hit:5 https://download.docker.com/linux/ubuntu focal InRelease
Ign:6 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 InRelease
Hit:7 https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 Release
Get:8 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:9 http://ppa.launchpad.net/hluk/copyq/ubuntu focal InRelease
Hit:10 https://artifacts.elastic.co/packages/oss-7.x/apt stable InRelease
Hit:11 https://repos.influxdata.com/ubuntu focal InRelease
Hit:12 https://dl.google.com/linux/chrome/deb stable InRelease
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,509 kB]
Step 3: Install Flutter
There are multiple ways to install flutter on Linux based systems. Here we will see the installation by two different ways. You can choose to install using either of them.
a) Using Snapd
If you have snap utility available in your System then you can install flutter by running snap install flutter --classic
command as shown below.
root@cyberithub:~# snap install flutter --classic
flutter 0+git.671983f from Flutter Team* installed
b) Using Tar File
If you don't have snap utility then you can install it through flutter tar file. You can go to Official download page and get the latest version to download. In our case, as of now 2.8.1
is the latest version so we are downloading this version by using below wget command.
root@cyberithub:~# wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_2.8.1-stable.tar.xz
--2022-01-19 20:28:18-- https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_2.8.1-stable.tar.xz
Resolving storage.googleapis.com (storage.googleapis.com)... 2404:6800:4009:829::2010, 2404:6800:4009:828::2010, 2404:6800:4009:827::2010, ...
Connecting to storage.googleapis.com (storage.googleapis.com)|172.217.166.80|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 635212292 (606M) [application/x-gtar]
Saving to: βflutter_linux_2.8.1-stable.tar.xzβ
flutter_linux_2.8.1-stable.tar.xz 100%[============================================================================>] 605.79M 18.6MB/s in 34s
2022-01-19 20:37:38 (17.6 MB/s) - βflutter_linux_2.8.1-stable.tar.xzβ saved [635212292/635212292]
Then extract the package by using tar -xvf flutter_linux_2.8.1-stable.tar.xz command. This will extract the package in a local flutter directory.
root@cyberithub:~# tar -xvf flutter_linux_2.8.1-stable.tar.xz
..................................................
flutter/dev/automated_tests/integration_test/
flutter/dev/automated_tests/integration_test/trivial_widget_expectation.txt
flutter/dev/automated_tests/integration_test/trivial_widget_test.dart
flutter/dev/automated_tests/integration_test/exception_handling_test.dart
flutter/dev/automated_tests/integration_test/exception_handling_expectation.txt
flutter/dev/benchmarks/
flutter/dev/benchmarks/platform_views_layout_hybrid_composition/
flutter/dev/benchmarks/platform_views_layout_hybrid_composition/lib/
flutter/dev/benchmarks/platform_views_layout_hybrid_composition/lib/main.dart
flutter/dev/benchmarks/platform_views_layout_hybrid_composition/lib/android_platform_view.dart
flutter/dev/benchmarks/platform_views_layout_hybrid_composition/README.md
flutter/dev/benchmarks/platform_views_layout_hybrid_composition/pubspec.lock
...........................................................
Then export the flutter bin directory using export PATH="$PATH:`pwd`/flutter/bin"
command. Be mindful that this is just a temporary export which will not work if you close your current session. So to make it permanent it is always recommended to export your path from either ~/.profile
or ~/.bashrc
.
root@cyberithub:~# export PATH="$PATH:`pwd`/flutter/bin"
Step 4: Check Flutter Version
After successful installation, you can verify the current installed version by using flutter --version
command as shown below.
root@cyberithub:~# flutter --version
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
/
π
Flutter 2.8.1 β’ channel stable β’ https://github.com/flutter/flutter.git
Framework β’ revision 77d935af4d (5 weeks ago) β’ 2021-12-16 08:37:33 -0800
Engine β’ revision 890a5fca2e
Tools β’ Dart 2.15.1
Step 5: Check SDK Path(Optional)
Once you have the snap installed, you can use flutter sdk-path
command to display your flutter SDK path. It is important to note here that below command will only work if you have installed flutter as a snap.
root@cyberithub:~# flutter sdk-path
Initializing Flutter
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 147k 100 147k 0 0 154k 0 --:--:-- --:--:-- --:--:-- 154k
Downloading https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_2.8.1-stable.tar.xz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 605M 100 605M 0 0 16.9M 0 0:00:35 0:00:35 --:--:-- 18.6M
Flutter initialized
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
/
π
Flutter 2.8.1 β’ channel stable β’ https://github.com/flutter/flutter.git
Framework β’ revision 77d935af4d (5 weeks ago) β’ 2021-12-16 08:37:33 -0800
Engine β’ revision 890a5fca2e
Tools β’ Dart 2.15.1
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Welcome to Flutter! - https://flutter.dev β
β β
β The Flutter tool uses Google Analytics to anonymously report feature usage β
β statistics and basic crash reports. This data is used to help improve β
β Flutter tools over time. β
β β
β Flutter tool analytics are not sent on the very first run. To disable β
β reporting, type 'flutter config --no-analytics'. To display the current β
β setting, type 'flutter config'. If you opt out of analytics, an opt-out β
β event will be sent, and then no further information will be sent by the β
β Flutter tool. β
β β
β By downloading the Flutter SDK, you agree to the Google Terms of Service. β
β Note: The Google Privacy Policy describes how data is handled in this β
β service. β
β β
β Moreover, Flutter includes the Dart SDK, which may send usage metrics and β
β crash reports to Google. β
β β
β Read about data we send with crash reports: β
β https://flutter.dev/docs/reference/crash-reporting β
β β
β See Google's privacy policy: β
β https://policies.google.com/privacy β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
/root/snap/flutter/common/flutter
Step 6: Run Flutter Doctor
You can run flutter doctor
to check if there are any dependencies you need to install to complete the setup. This command will check your environment and display the summary with recommendation and link from where you need to download the components. For example, in my case Android Studio is missing so it is asking to install this component from a certain location as shown below.
root@cyberithub:~# flutter doctor
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
/
π
Running "flutter pub get" in flutter_tools... 15.0s
Doctor summary (to see all details, run flutter doctor -v):
[β] Flutter (Channel stable, 2.8.1, on Ubuntu 20.04.3 LTS 5.11.0-46-generic, locale en_IN)
[β] Android toolchain - develop for Android devices
β Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
[β] Chrome - develop for the web
[!] Android Studio (not installed)
[β] Connected device (1 available)
! Doctor found issues in 2 categories.
Step 7: Run Flutter Devices
You can check for any connected devices using flutter devices
command. If chrome is already installed then this command will output a chrome device that opens the chrome browser with your app running and a web server that provides the URL serving the app.
root@cyberithub:~# flutter devices
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
/
π
1 connected device:
Chrome (web) β’ chrome β’ web-javascript β’ Google Chrome 97.0.4692.71
Step 8: Create a New App
To create a new app, you need to use flutter create <app_name>
syntax. For example, here we are creating a new app called myapp
using flutter create myapp
command. This will create an app with web support in addition to the mobile support.
root@cyberithub:~# flutter create myapp
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
/
π
Creating project myapp...
myapp/test/widget_test.dart (created)
myapp/pubspec.yaml (created)
myapp/README.md (created)
myapp/lib/main.dart (created)
myapp/.idea/runConfigurations/main_dart.xml (created)
................................................
myapp/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png (created)
myapp/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png (created)
myapp/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md (created)
Running "flutter pub get" in myapp... 6.5s
Wrote 81 files.
All done!
In order to run your application, type:
$ cd myapp
$ flutter run
Your application code is in myapp/lib/main.dart.
Step 9: Run Flutter App
Once the app created successfully, you can go inside the app and launch it by using flutter run
command. This will serve your app from localhost in Google Chrome.
NOTE:
flutter run -d chrome
command. Since in our case we have only chrome so running flutter run will by default launch the app in Chrome browser.root@cyberithub:~# cd myapp/ root@cyberithub:~/myapp# flutter run Woah! You appear to be trying to run flutter as root. We strongly recommend running the flutter tool without superuser privileges. / π Launching lib/main.dart on Chrome in debug mode... Waiting for connection from debug service on Chrome... 22.1s ...................................................
Step 10: Uninstall Flutter
If flutter is installed as snap then you can uninstall it by using snap remove flutter
command as shown below.
root@cyberithub:~# snap remove flutter
flutter removed