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
|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
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – 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.
- 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
- 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:
#!/bin/bash echo "Hello World!"
Save your file as
- 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 command: hello.sh modules: - name: hello buildsystem: simple build-commands: - install -D hello.sh /app/bin/hello.sh sources: - type: file path: hello.sh
Save this file as
org.flatpak.Hello.ymland store it in the same directory as your application or
hello.shfile created above.
- Next, use the
flatpak-buildercommand to create the application.
$ flatpak-builder build-dir org.flatpak.Hello.yml
- 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
- Then, we can run our application with:
$ flatpak run org.flatpak.Hello
- 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
--repooption. We will call our repo “myrepo.”
$ flatpak-builder --repo=myrepo --force-clean build-dir org.flatpak.Hello.yml
- 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
--useroption here to avoid installing the application for system wide use. You may omit this option if you wish.
- Finally, we can run our new application the same as before:
$ flatpak run org.flatpak.Hello
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.