Packaging and Distributing Flutter Desktop Apps : The Missing Guide for Open Source & Indie Developers — Creating Linux Debian (.deb) & RPM (.rpm) builds [Part 3 of 3]
by Ashita Prasad (LinkedIn, Twitter), fluttergems.dev
Articles in this series:
- Introduction & creating macOS
.app
&.dmg
— Part 1 of 3 - Creating Windows
.exe
installer — Part 2 of 3 - Creating Linux Debian (
.deb
) & RPM (.rpm
) builds — Part 3 of 3 [This article]
In the previous articles of this series, we uncovered the motivation behind creating this step-by-step guide for packaging and distributing Flutter desktop apps the “indie” way or the open source way. We covered the entire process we follow (step-by-step) to build the macOS distribution (.dmg
) & the Windows installer (.exe
) of API Dash, an open source alternative to Postman that we have built completely using Flutter (GitHub repo👇).
In this article, we will go through the step-by-step process of creating Linux distributions (both .deb
& .rpm
) of your Flutter desktop app.
Packaging & Publishing Flutter Desktop App for Linux
To learn how to build & publish Linux app on Snap Store check out the official docs on integration & deployment.
In the Linux ecosystem, .deb
(Debian) & .rpm
(Red Hat Package Manager) are the two most widely used formats for software distribution. Based on the Linux distro, the end-user can choose the right package to install the Flutter application:
.deb
bundle is used to install an app in any Debian linux distribution like Debian, Ubuntu, Linux mint, etc.- Whereas,
.rpm
bundle is used to install a desktop app in any Red Hat linux distribution like Red Hat Linux, Fedora, Rocky, etc.
Based on the CPU architecture of the system which is being used to create the build, the corresponding target builds are created:
- Apple Silicon or ARM based to create
arm64
/aarch64
bundles. - Intel 64 bit to create
amd64
/x86_64
bundles.
Pre-requisites
You can either use a Linux machine or a Linux distro running on a VM to create linux builds of your Flutter desktop app.
Debian based distro (like Ubuntu) should be the preferred as you can build both .deb
& .rpm
builds in the same system. This is possible due to rpmbuild
& patchlf
libraries which can be installed using the following command in Ubuntu/Debian:
apt install rpm patchelf
To compile Flutter desktop app in Linux you would also need to install the following tools:
These tools can be installed by running the following command in the terminal:
sudo apt-get install clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev
Your build can break, in case any of the above tools are missing.
Creating a Debian (.deb) Bundle
Step 1
Now, let us start with the process of creating the builds.
We will use the flutter_distributor
tool to create the Linux packages/bundles of our Flutter desktop app.
It can be easily installed and activated using the following command:
dart pub global activate flutter_distributor
Step 2
Create distribute_options.yaml
file in your project root directory. The config file is used to provide the specifications for various builds like for different target platforms or for different environments like development, QA or production.
Let us create a release specification for our debian build. The contents of the distribute_options.yaml
file is provided below:
output: dist/
releases:
- name: dev
jobs:
- name: release-dev-linux-deb
package:
platform: linux
target: deb
build_args:
enable-experiment: records
The name of the release is specified as dev
and inside it there can be multiple jobs, like to build for linux, android, ios, etc.
We created a single job with name release-dev-linux-deb
where we specified our platform and target as linux
& deb
. Additional command line arguments or compile time constants can also be specified via build_args
like in this case we provided records
value to the enable-experiment
flag to indicate that the experimental Dart records feature is being used.
Step 3
Create a new directory named packaging
inside the linux
folder in the project home. This folder will contain the config files used for our linux builds.
As we want to create a debian build, create a new folder named deb
inside the packaging
folder.
Now, create make_config.yaml
inside this folder. This file will be used to specify the details to build the debian bundle.
The final path of this file is:
/path/to/project/linux/packaging/deb/make_config.yaml
In make_config.yaml
, we can specify all details that are required to create the .deb
build like:
- The display name for the application
- The name of the package (lowercase, nospace — actual name which can be executed via terminal)
- Maintainer information
- App icon path
- Metadata such as app category & keywords
- External dependencies
- Other required information used for creating the build.
A sample make_config.yaml
spec is provided below:
display_name: API Dash
package_name: apidash
maintainer:
name: Ashita Prasad
email: ashita@xyz.com
priority: optional
section: x11
installed_size: 15700
dependencies:
- mpv
essential: false
icon: linux/assets/apidash.png
postuninstall_scripts:
- echo "Sorry to see you go."
keywords:
- API
- API Client
generic_name: API Client
categories:
- Development
- Utility
startup_notify: true
Step 4
Your Flutter app might be using packages that have external dependencies that must be specified in the make_config.yaml
file as shown below:
These dependencies need to be installed on the end users system in order to use the application. To figure out these dependencies, check the pub dev page of packages that have been used in the project. Developers usually specify the dependencies in the readme file.
For example, flutter_secure_storage
has the following external dependencies required to run the app using it:
libsecret-1-0
libjsoncpp1
In case only debian dependencies are mentioned and you also want the corresponding rpm
dependencies, you can check out pkgs.org to find their rpm equivalent.
Step 5
Run the following flutter_distributor
command to generate the build.
flutter_distributor release --name=dev --jobs=release-dev-linux-deb
Step 6
Once the build is successfully completed, the location of the bundle will be displayed.
To distribute the bundle via GitHub, you can create a new release and attach the .deb
file as shown below.
Once the release is published, the deb
bundle will be available for download to all users. It can be installed using the following commands:
sudo dpkg -i app.deb
or
sudo apt install ./app.deb
Creating a RPM (.rpm) Bundle
To create a RPM build of your Flutter desktop app for Red Hat-based Linux Distributions (Fedora, Rocky, AlmaLinux, CentOS, RHEL, etc.), the steps are exactly same as for the debian build provided above with slight differences in the steps mentioned below:
Step 1
Same as for .deb
Step 2
Modify the distribute_options.yaml
file in your project root directory to add a new job release-dev-linux-rpm
to target rpm
.
output: dist/
releases:
- name: dev
jobs:
- name: release-dev-linux-deb
package:
platform: linux
target: deb
build_args:
enable-experiment: records
- name: release-dev-linux-rpm
package:
platform: linux
target: rpm
build_args:
enable-experiment: records
Step 3
Create a new folder named rpm
inside the linux/packaging
folder.
Now, create make_config.yaml
inside this folder. This file will be used to specify the details to build the RPM package.
The final path of this file is:
/path/to/project/linux/packaging/rpm/make_config.yaml
In make_config.yaml
, we can specify all details that are required to create the .rpm
build like:
- The display name for the application
- App icon path
- Application description
- Maintainer information
- License
- Metadata such as app category & keywords
- External dependencies (
requires
) - Other required information used for creating the build.
A sample make_config.yaml
spec for RPM build is provided below:
display_name: API Dash
icon: linux/assets/apidash.png
summary: A beautiful lightweight open-source cross-platform API Client
group: Applications/Development Tools
vendor: Ashita Prasad
packager: Ashita Prasad
packagerEmail: ashita@xyz.com
license: ASL 2.0
url: https://github.com/foss42/apidash
build_arch: aarch64
requires:
- mpv
keywords:
- API
- API Client
generic_name: API Client
categories:
- Development
- Utility
startup_notify: true
Note: The external dependencies are provided under requires
and the process is same as described in Step 4 for debian build.
Step 5
Run the following flutter_distributor
command to generate the RPM build.
flutter_distributor release --name=dev --jobs=release-dev-linux-rpm
Step 6
Once the build is successfully completed, the location of the bundle will be displayed.
To distribute the bundle via GitHub, you can create a new release and attach the .rpm
file as shown below.
Once the release is published, the rpm
package will be available for download to all users. It can be installed using the following commands:
sudo dnf localinstall ./app.rpm
or
sudo rpm -i app.rpm
or
sudo yum localinstall ./app.rpm
Closing Notes
In this article, we learnt how to create a Debian (.deb
) and RPM (.rpm
) distribution for a Flutter desktop app the “indie” or open source way. You can check out the other article in this series to learn how to do the same for other desktop platforms.
- Introduction & creating macOS
.app
&.dmg
— Part 1 of 3 - Creating Windows
.exe
installer — Part 2 of 3
In case you have any doubts or queries please feel free to comment below or drop in our Discord Server.
This article is brought to you by Flutter Gems, a curated list of top Dart and Flutter packages that are categorized based on functionality. Do check it out below 👇