How to Create and Publish Flatpak Packages

As an application developer, you may be interested in packaging and distributing your work through Flatpak. Lots of developers choose to use Flatpak because it allows them to deploy their application across a variety of different Linux system, without needing to worry about individual dependencies and differences between distributions. There are also many public software repositories, like FlatHub, where you can upload your work and not need to worry about hosting it yourself.

In this tutorial, you will see how to get started with developing Flatpak packages by creating and publishing your first Flatpak app. Follow along with the step by step instructions below as we take you through the steps to create, package, and publish your new Flatpak program on Linux.

In this tutorial you will learn:

  • How to install Flatpak SDK
  • How to create a new application and manifest
  • How to add your application to a repo
  • How to install and run your Flatpak application
How to Create and Publish Flatpak Packages
How to Create and Publish Flatpak Packages
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software Flatpak package manager
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Create and Publish Flatpak Packages step by step instructions

The following steps assumme that you have at least installed Flatpak on your system already and enabled the FlatHub remote repository. From there, we will install an SDK and get started with packaging our application.

  1. First, we will need to download and install a runtime and SDK, as every Flatpak app requires a runtime, and the SDK is required in order to build and package the app. Install the Freedesktop 22.08 runtime with the following command:
    $ flatpak install flathub org.freedesktop.Platform//22.08 org.freedesktop.Sdk//22.08
  2. Create your app. If you do not already have an application that you wish to package, and just want to run this as a test, create a simple Hello World script:
    echo "Hello World!"

    Save your file as

  3. You will also need a manifest file alongside your application. Again, just for testing purposes, we can create a simple Hello World manifest file:
    app-id: org.flatpak.Hello
    runtime: org.freedesktop.Platform
    runtime-version: '22.08'
    sdk: org.freedesktop.Sdk
      - name: hello
        buildsystem: simple
          - install -D /app/bin/
          - type: file

    Save this file as org.flatpak.Hello.yml and store it in the same directory as your application or file created above.

  4. Next, use the flatpak-builder command to create the application.
    $ flatpak-builder build-dir org.flatpak.Hello.yml
    Building our Flatpak package
    Building our Flatpak package
  5. Next, we will test the installation of our new package by using the following command:
    $ flatpak-builder --user --install --force-clean build-dir org.flatpak.Hello.yml
  6. Then, we can run our application with:
    $ flatpak run org.flatpak.Hello
  7. If everything works as expected so far, we can proceed to put our application in a repository. Here we will be creating our own repository, but if you wanted to put your app online, you would need to follow the submission instructions for the site you want to upload to (e.g., FlatHub). We will build the app once again, but this time add the --repo option. We will call our repo “myrepo.”
    $ flatpak-builder --repo=myrepo --force-clean build-dir org.flatpak.Hello.yml
  8. Next, we can add the new repository to Flatpak, and then install our application from the repository.
    $ flatpak --user remote-add --no-gpg-verify myrepo myrepo
    $ flatpak --user install myrepo org.flatpak.Hello

    Note that we use the --user option here to avoid installing the application for system wide use. You may omit this option if you wish.

  9. Finally, we can run our new application the same as before:

    $ flatpak run org.flatpak.Hello

Closing Thoughts

In this tutorial, we saw how to create, publish, and install a Flatpak application on a Linux system. This allows developers to package and distribute their software through the Flatpak package manager, and ultimately decide whether they wish to host their own software repository or submit their work to an online Flatpak remote.

Comments and Discussions
Linux Forum