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
Step 1: Prerequisites
a) You should have a running
Ubuntu 20.04 LTS Server.
b) You should have
root access to run privileged commands.
c) You should have
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)|184.108.40.206|: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
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.
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.
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
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.
flutter run -d chromecommand. 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