How to create a Flatpak package step by step in Linux

Last update: 04/12/2025
Author Isaac
  • Flatpak allows you to package applications and their dependencies into portable, isolated containers for multiple distributions. Linux.
  • Flatpak packages are based on shared runtimes, comprehensive metadata, and a clear structure of files, icons, and AppData.
  • Flathub acts as a central repository for Flatpak applications, although its publishing process requires detailed manifests and compilation without network access.

Step-by-step guide to creating a Flatpak package

If you work with GNU/Linux and are interested in distributing your applications easily, you'll eventually come across Flatpak. This packaging format has become one of the most popular ways to deliver desktop applications that work the same on almost any distribution, without having to wrestle with dependencies or the current package manager.

In this guide, we'll see how to create a Flatpak package step by step, from scratch and in great detail . You'll learn exactly what Flatpak is, why it's so important today, what you need to prepare in your environment, how to structure the package, what metadata you need, how to install it, test it, export it to a repository, and even what it means to upload it to Flathub. All of this is presented with a practical approach and in an accessible style so you don't find it daunting.

What is Flatpak and why has it become so important?

What is Flatpak and how does it work?

Flatpak is a container-based software packaging and distribution technology for Linux . The idea is very simple yet powerful: instead of relying on each distribution's package manager, the application is packaged along with the libraries and dependencies it needs and runs in a sandbox environment that guarantees consistent behavior across any compatible distribution.

In practice, a Flatpak package includes the application and all the libraries necessary for it to function , without interfering with other programs on the system. This avoids the classic dependency hell, reduces conflicts, and gives the developer direct control over how their application is distributed and updated, without having to wait for a distribution maintainer to package it.

To achieve this, Flatpak relies on shared runtimes . These runtimes provide a common foundation (for example, a specific version of the GNOME platform) on which multiple applications run. This way, you don't have to package absolutely everything in each app, but only what isn't already included in the runtime, saving space and simplifying maintenance.

Furthermore, Flatpak applications run in a sandbox with their own permissions system . This model allows you to control access to resources such as the file system, network, Bluetooth, audio, and the graphics server (X11/Wayland). This isolation enhances security and limits the potential damage from a malicious or corrupted application.

One of the major advantages for users and administrators is that Flatpak packages are installed and updated independently of the distribution's package manager . You can have your Flatpak applications coexisting with native packages without them interfering with each other, and even manage multiple versions of the same app simultaneously.

Advantages and disadvantages of Flatpak compared to other formats

Advantages and disadvantages of Flatpak

The GNU/Linux ecosystem has always had multiple packaging systems: deb, rpm, AppImage, Snap, Flatpak… Each one solves the software distribution problem in its own way. Flatpak stands out especially in the desktop environment, and it's no coincidence that many major distributions support it by default.

Among the main advantages of Flatpak from the user's point of view we can highlight:

  • Simple and universal installation: With a single package format you can install the same app on different distributions (Debian, Fedora, openSUSE, Arch, etc.) as long as they have Flatpak enabled.
  • Improved insulation and security: The applications run in a sandbox with explicit permissions, reducing risks and conflicts between programs.
  • Automatic and centralized updates: With one command you can update all your apps Flatpak, without depending on the distro cycle.
  • Coexistence of multiple versions: It is possible to have more than one version of the same application installed, which is very useful for developers or testing environments.
  • Fewer compatibility issues: Dependencies are controlled by the package itself and/or the runtime, thus minimizing conflicts with system libraries.

For developers, Flatpak is also very attractive. It allows you to publish your application directly without relying on a maintainer to package it for each distribution . Once you upload your app (for example, to Flathub), any Linux user with Flatpak enabled can install it with one or two commands , or even from their environment's graphical software store.

This immediacy means that a new version of your application can reach users on different distributions simultaneously , which is especially useful on distributions with slow release cycles where official packages take time to update. Furthermore, the runtime environment offers a homogeneous foundation, thus reducing the number of library combinations that need to be supported.

  How to highlight syntax in Notepad++ step by step and without complications

It's not all advantages. There are some drawbacks and tolls to consider :

  • Package sizes: Flatpak packages typically take up more space than traditional native packages because they include additional dependencies or share large runtimes. This results in more downloads and increased disk usage.
  • Slight performance penalty: Because it runs in a sandbox and has extra layers of abstraction, in some cases there may be a small impact on performance, although it is usually minimal for most users.
  • Dependence on Flatpak repositories: If an app is only distributed via Flathub or another Flatpak repository, you are tied to that repo being kept alive and up-to-date.
  • Packaging complexity: Creating a well-made Flatpak, especially for deployment on Flathub, can be much more laborious than it initially seems, particularly regarding dependencies and metadata.

Furthermore, compared to other solutions like Snap, the packaging and deployment experience can be, frankly, somewhat more confusing . The official instructions are rather scattered, and if your goal is to publish to Flathub, there are even more steps and requirements to meet.

How Flatpak works on a technical level

How Flatpak works

To fully understand how to create a Flatpak package, it's very helpful to have a clear understanding of its architecture. Flatpak is based on two fundamental pieces: runtimes and applicationsA runtime is a shared execution environment, such as org.gnome.Platform/x86_64/3.22, which provides a common base of libraries and components.

A Flatpak application declares in its metadata which runtime it needs to function . This way, multiple apps can use the same runtime, saving space and ensuring compatibility. The result is something like, "the app relies on a stable and well-known platform, and anything not included in that platform is packaged within the app itself."

The applications run within isolated containers that restrict access to critical resources . This isolation is managed through configurable permissions: network access, file system directories, input devices, audio (PulseAudio), graphics server (X11/Wayland), D-Bus for inter-process communication, etc.

A key idea is that dependencies are managed more predictably . Instead of relying on system library versions, which can vary greatly between distributions and versions, the developer knows in advance which runtime will be available and, if something newer or more specific is needed, includes it directly in the package.

Distribution is typically handled through repositories like Flathub, which acts as a centralized repository for Flatpak applications . From there, users can search for, download, and install apps with a single command or via the graphical store. It's also possible to create custom repositories, which is very useful in corporate or educational environments where applications are deployed in a controlled manner.

Prerequisites for creating a Flatpak package

Before you start packaging, you need to understand what Flatpak requires for everything to work. There are three basic requirements: having Flatpak installed, having a suitable runtime, and defining the package structure.

In virtually any modern Linux distribution, you can install Flatpak from the distribution's own package manager . In Arch Linux, for example, if you install GNOME with the gnome and gnome-extra package groups , Flatpak is automatically installed as a dependency. Otherwise, you can install it explicitly using the distribution's package manager (pacman, apt, dnf, zypper, etc.).

The second step is configure at least one runtime environmentFor most desktop applications, it is common to rely on platforms such as org.gnome.Platform or those provided by KDE, always in the architecture and version you are going to use, for example x86_64/3.22.

Once you have Flatpak and the runtime ready, it's time to think about the package structure and in the fully qualified application nameFlatpak uses a convention of the type com.distribuidor.App o org.test.HelloThis is similar to reverse domain identifiers. This identifier will be used in all commands and in the manifest.

Finally, you'll need the development tools corresponding to your language or technology, because part of the process involves compiling or preparing the binaries that will then be placed inside the Flatpak container . Packaging a small shell script is not the same as packaging a complex app in C++, Java, Python , or Electron.

Basic structure of a Flatpak package

A Flatpak package is not just binaries. It includes several essential elements that describe the application and allow it to be integrated with the desktop . Typical components of a Flatpak package include:

  • AppData (application metadata): Information files about the app (usually in XML format) that include description, screenshots, category, link to the official website, etc. These are essential for software stores to display the app correctly.
  • Icons in various sizes: Images adapted to different screen densities, including high-resolution displays. They are installed in standard paths recognized by the desktop environment.
  • .desktop files: Shortcuts that allow you to launch the application from the menu, the application launcher, or the dock of the desktop environment.
  • D-Bus configuration and other services: Definitions for communication with the system message bus, as well as integration with PulseAudio for sound and X11/Wayland for graphical representation.
  • Application-specific files: Executables, scripts, additional libraries, graphic resources, etc. In short, everything necessary for your program to work.
  What to do if Microsoft Edge won't load web pages

To better understand the structure, imagine you're creating a very simple example, a "Hello World" program packaged with Flatpak. You could start by creating a directory hierarchy like this :

mkdir hello
mkdir hello/files
mkdir hello/files/bin
mkdir hello/export

In the folder hello/files/bin would you place the executable or script that you want to run, and in hello You would have the typical Flatpak metadata, such as the application file with the section [Application] where the name and launch order are specified.

A simplified example of metadata might look something like this, where the identifier, runtime, and main command to be executed are defined :

[Application] name=org.test.Hello
runtime=org.gnome.Platform/x86_64/3.22
command=hello.sh

And the file hello.sh could be a simple shell script with this content, which would be installed within files/bin:

#!/bin/sh
echo "Hello world, from a sandbox"

This example is very basic, but it illustrates the idea that the Flatpak package contains, on the one hand, the application files and, on the other hand, all the information to integrate and run it correctly within a specific execution environment.

General steps to create a Flatpak package step by step

Based on the above, we can summarize the basic workflow for packaging an application in Flatpak. These steps are valid for both local testing and more serious releases (although, as we will see, Flathub adds extra requirements):

  1. Install Flatpak on your distribution If you don't already have it, use the native package manager (apt, dnf, pacman, etc.).
  2. Configure a suitable runtimeFor example, by adding Flathub as a repository and downloading the runtime required for your app.
  3. Define the package structure and its full identifier (of the kind com.tuempresa.TuApp), in addition to creating the file folders, metadata, icons, AppData, etc.
  4. Build the package and export it to a repository local or remote, for example with a command like flatpak build-export repo helloWhere repo is the repository folder and hello It is the directory with the build.
  5. Install the package from that repository and test it. to verify that everything works as expected within the sandbox.

The command flatpak build-export can be combined with GPG signatures for to guarantee the authenticity of the developer and the integrity of the packageThis is especially interesting when distributing applications in environments where cryptographic verification is important.

Keep in mind that the steps above describe a fairly straightforward workflow geared towards local builds . When we talk about Flathub, things get a bit more complicated, because the repository doesn't accept pre-compiled packages; instead, it compiles Flatpaks on its own servers with restricted network access.

Install, run, and manage Flatpak applications from the terminal

Once you have your package, or want to try others, managing Flatpak applications from the command line is quite simple . Let's look at some typical examples that will help you understand how your own package would be used once it's packaged.

Imagine you have created a small repository called tutorial-repo that contains your sample application org.test.Hello. To add that repository and install the app only for your userYou could use:

flatpak --user remote-add --no-gpg-verify tutorial-repo repo
flatpak --user install tutorial-repo org.test.Hello
flatpak run org.test.Hello

Parameter --user indicates that the installation is performed in the user's personal directory, without requiring administrator permissions and without affecting the rest of the system accountsIt is ideal for multi-user environments where each person can decide which Flatpak applications they want to have.

A classic example is installing a game like GNOME Chess just for your user account. The command might look like this (assuming you're using Flathub as your repository):

flatpak install --user https://dl.flathub.org/repo/appstream/org.gnome.Chess.flatpakref

You can install applications by directly specifying the reference file .flatpakref, as with GIMP from Flathub, using something like:

flatpak install https://dl.flathub.org/repo/appstream/org.gimp.GIMP.flatpakref

To keep everything up to date, the command flatpak update It is responsible for updating installed applications.You can run it periodically or even integrate it into administration scripts, as is done in some educational or corporate environments where applications are deployed in system mode for all users.

In addition to installing and updating, Flatpak lets you list, uninstall, and clean up applications and runtimes you no longer use. The cleanup command is especially useful for removing orphaned libraries and dependencies, freeing up disk space after uninstalling Flatpak applications.

Flathub, repositories and Flatpak application deployment

Flathub has established itself as the main and most well-known repository for Flatpak applications . It's where most users look for new programs and where many developers publish updated versions of their desktop applications.

  All about the Windows Public Folder and how to use it

Flathub offers a huge variety of software, organized into categories such as audio and video, development, education, games, graphics, communication, productivity, science, utilities, and more . It features well-known applications like VLC, GIMP, LibreOffice, Audacity, Steam , Inkscape, Blender, Signal, Telegram, Calibre, and many others.

From the Flathub website you can Find an application, click the INSTALL button and get the reference .flatpakref, which is then passed to the command flatpak installThis reference contains the information necessary for Flatpak to know from which remote to download the app, which runtime to use, etc.

If you're in a more controlled environment, such as a company or school, you can also create your own repositories and publish your applications there . Many educational institutions, for example, use Ansible or other automation tools to deploy Flatpak applications in system mode, making them available to all users on the computer.

System mode installation usually requires administrative privileges, but It offers the advantage that the apps are made available in a centralized manner.For its part, the installation with --user It is ideal for giving flexibility to each person without altering the machine's base software set.

Create a Flatpak package to publish it on Flathub

Here comes one of the trickiest parts. Building a working Flatpak on your machine is only half the story . If you want to publish it on Flathub, the process has additional requirements and limitations that you should be aware of from the start to avoid frustration.

To begin with, the instructions on the main Flatpak website focus on a fairly "open" build flow , where your build environment can access the network to download dependencies, clone repositories, and so on. However, Flathub compiles packages on its own servers, and the build process there doesn't have internet access. This means that everything you need must be described in the manifest with well-defined source URLs.

In other words, if your application depends on multiple external libraries or modules, You need to explicitly add the sources for each dependency in the Flatpak manifest.even if you already have one requirements.txt In the case of Python or another dependency file in your technology, this may force you to use (sometimes unpolished) helper scripts to generate these sections, and you'll still have to manually check things like build dependencies.

The practical consequence is that resolving all dependencies and getting netless compilation to work can take hours , especially in complex applications or those with many external libraries. In some high-level languages, such as Python, finding all the correct build dependencies can be quite tedious.

Another important point is that you can't use just any runtime you want on Flathub . You can only rely on the runtimes hosted on Flathub itself, which sometimes forces you to manually compile and include more dependencies than you'd like. This multiplies the packaging work and the amount of things you have to maintain in the long run.

In addition to the manifest and dependencies, Flathub requires a fairly detailed metadata file , including information such as a lengthy description, screenshots, links, licenses, categories, and, in many cases, release notes for each update. This necessitates ongoing maintenance every time you release a new version.

The deployment process is also not trivial. To publish to Flathub, you need to request a specific repository within the Flathub organization on GitHub , go through a review process, and configure actions or workflows that integrate with Flathub's build infrastructure. The documentation mentions GitHub Actions, but it doesn't always clearly explain how these actions fit with the organization's official repository.

For all these reasons, some developers, after trying it out, say that creating a Flatpak for Flathub can be frustrating and very time-consuming , to the point of considering alternative formats like Snap when the goal is a more direct and less frictionless deployment. Even so, the advantage of reaching a very broad user base across multiple distributions makes the effort worthwhile in many cases.

Isaac

Isaac

Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.