Construire votre premier Flatpak

Ce tutoriel fournit une rapide introduction pour la construction de flatpaks. À l’intérieur, vous apprendrez comment créer une application Flatpak basique, qui peut être installée et lancée.

Afin de compléter ce tutoriel, vous devriez avoir suivi le guide de configuration sur Vous aurez aussi besoin d’avoir installé flatpak-builder, qui est habituellement disponible dans le même dépôt que le paquet flatpak package.

1. Installer un runtime et le SDK correspondant

Flatpak requires every app to specify a runtime that it uses for its basic dependencies. Each runtime has a matching SDK (Software Development Kit), which contains all the things that are in the runtime, plus headers and development tools. This SDK is required to build apps for the runtime.

In this tutorial we will use the Freedesktop 18.08 runtime and SDK. To install these, run:

$ flatpak install flathub org.freedesktop.Platform//18.08 org.freedesktop.Sdk//18.08

2. Créer une application

L’application qui va être créée dans ce tutoriel est un simple script. Pour le créer, copiez le code suivant:

echo "Hello world, from a sandbox"

Maintenant collez cela dans un fichier vide et sauvez-le sous le nom

3. Ajouter un manifeste

Each Flatpak is built using a manifest file which provides basic information about the application and instructions for how it is to be built. To add a manifest to the hello world app, add the following to an empty file:

    "app-id": "org.flatpak.Hello",
    "runtime": "org.freedesktop.Platform",
    "runtime-version": "18.08",
    "sdk": "org.freedesktop.Sdk",
    "command": "",
    "modules": [
            "name": "hello",
            "buildsystem": "simple",
            "build-commands": [
                "install -D /app/bin/"
            "sources": [
                    "type": "file",
                    "path": ""

Now save the file alongside and call it org.flatpak.Hello.json.

In a more complex application, the manifest would list multiple modules. The last one would typically be the application itself, and the earlier ones would be dependencies that are bundled with the app because they are not part of the runtime.

4. Construire une application

Now that the app has a manifest, flatpak-builder can be used to build it. This is done by specifying the manifest file and a target directory:

$ flatpak-builder build-dir org.flatpak.Hello.json

This command will build each module that is listed in the manifest and install it to the /app subdirectory, inside the build-dir directory.

5. Test the build

To verify that the build was successful, run the following:

$ flatpak-builder --run build-dir org.flatpak.Hello.json

Congratulations, you’ve made an app!

Keep in mind that using --run won’t result in a sandbox with the same permissions as the final app, as such it shouldn’t be relied upon beyond basic testing.

6. Put the app in a repository

Before you can install and run the app, it first needs to be put in a repository. This is done by passing the --repo argument to flatpak-builder:

$ flatpak-builder --repo=repo --force-clean build-dir org.flatpak.Hello.json

This does the build again, and at the end exports the result to a local directory called repo. Note that flatpak-builder keeps a cache of previous builds in the .flatpak-builder subdirectory, so doing a second build like this is very fast.

This second time we passed in --force-clean, which means that the previously created build-dir directory was deleted before the new build was started.

7. Install the app

Now we’re ready to add the repository that was just created and install the app. This is done with two commands:

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

The first command adds the repository that was created in the previous step. The second command installs the app from the repository.

Both these commands use the --user argument, which means that the repository and the app are added per-user rather than system-wide. This is useful for testing.

Note that the repository was added with --no-gpg-verify, since a GPG key wasn’t specified when the app was built. This is fine for testing, but for official repositories you should sign them with a private GPG key.

8. Run the app

All that’s left is to try the app. This can be done with the following command:

$ flatpak run org.flatpak.Hello

This runs the app, so that it prints “Hello world, from a sandbox”.