flatpak

Flatpak is a utility for software deployment and package management for Linux. It is advertised as offering a sandbox environment in which users can run application software in isolation from the rest of the system. Flatpak was developed as part of the freedesktop.org project and was originally called xdg-app.

Snap vs Flatpak

Snaps and Flatpaks are often compared to each other because they both make it super easy for Linux users to get the latest versions of desktop applications. If a Linux user wants to install the latest version of apps like Slack, Krita or Blender, either tool will work just fine. There is one fundamental difference between Snaps and Flatpaks, however. While both are systems for distributing Linux apps, snap is also a tool to build Linux Distributions.

Flatpak is designed to install and update “apps”; user-facing software such as video editors, chat programs and more. Your operating system, however, contains a lot more software than apps. It contains a kernel, printer drivers, audio subsystems and more. While Flatpak assumes this software is installed using a traditional package manager, snaps can install anything. These are some examples.

  • There is current work ongoing to put the entire Linux printing stack inside of a snap. This has the advantage that printer drivers can be updated independently from the operating system. Once this work is complete, every single Ubuntu version will be able to use the latest printer drivers. Trying to use new printers on old Linux distributions can be very frustrating, and installing newer printer drivers can be risky. Having the printing stack in a snap will solve this issue.
  • A few years ago, Ubuntu drastically changed the system theme. When the "CommuniTheme" initiative started, they wanted an easy way to make the latest updates of the theme available to users immediately. Normally, a system theme is shipped together with the distro, so users do not get theme updates after the distro releases. For “CommuniTheme”, however, they fixed this by putting the system theme inside of a snap. Because of this, users got updates to their theme every day, instead of every 6 months. This is again not something Flatpak was built for. Flatpak applications can update their own theme, but it is not possible to ship the system theme as a Flatpak. This is because Flatpak was designed for distributing apps, not building an entire Linux distribution.
  • Even the Linux kernel, the most fundamental part of a Linux distribution, can be put in a snap. This is used a lot for IoT devices such as routers and satellites. The impact of a broken kernel update is catastrophic if you require a rocket in order to plug a USB stick into the device. Snaps allow these devices to safely update their kernel and automatically roll back if something goes wrong during the process.

As a result, it’s possible to build an entire operating system using only snaps, which is exactly what Ubuntu Core is.

Flatpak was designed to give developers an easy way to bring their apps directly to users, and it does that job very well. The focused approach of Flatpak even has a big advantage: it’s a lot easier for a distribution to integrate with Flatpak because it does a lot less. The tradeoff is that it only provides app distribution; it doesn’t solve the issues of distributing entire operating systems. Fedora Silverblue, for example, creates an immutable desktop operating system by using Flatpak for app distribution and OSTree for distributing the OS itself.

Unfortunately, for my choice Linux distro (void linux), only Flatpak is available.

Install Flatpak

To install Flatpak, run the following:

sudo xbps-install -S flatpak

After installation

Once flatpak is installed, you can choose to install software system wide or on an per-user basis. The default is to install system wide which requires root priviledge (or sudo). You may also specify --system if you want to force system wide install.

To manage software on a per-user basis, use the --user option.

The best place to find software for Flatpak is flathub. You can browse the catalogue in https://flathub.org.

If you want to start installing software you need to first add the remote:

sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Or for per-user installation:

flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Afterwards you can install software:

sudo flatpak install pkg-id ...

Or per-user:

flatpak --user install pkg-id ...

Interesting flatpaks:

Basic commands

Search:

flatpak search gimp

Install:

sudo flatpak install flathub org.gimp.GIMP

Or:

flatpak --user install flathub org.gimp.GIMP

Note that the current version of flatpak will do a search, so you don't have to specify the ID.

Running applications:

flatpak run org.gimp.GIMP

This will automatically determine if the application was installed system-wide or on per-user basis. You can use the --system or --user flags to specify which to use if it was installed multiple times, otherwise the system-wide installation will be used.

Updating:

sudo flatpak update

Or:

flatpak --user update

This will update all installed applications.

List installed applications:

flatpak list

This will list applications and runtimes indicating if it was installed system wide or per-user. To list only applications:

flatpak list --app

Removing applications:

sudo flatpak uninstall org.gimp.GIMP

Or

flatpak --user uninstall org.gimp.GIMP

Keep in mind that uninstalling applications will not delete files in your $HOME directory. These are in $HOME/.var/app/$PKGID.

You need to manually delete these files.

Managing repositories

List remotes:

flatpak remotes

This gives a list of the existing remotes that have been added. The list indicates whether each remote has been added per-user or system-wide.

Add a remote:

sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Or:

flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Remove a remote:

sudo flatpak remote-delete flathub

Or:

flatpak --user remote-delete flathub

Troubleshooting

Flatpak has a few commands that can help you to get things working again when something goes wrong.

To remove runtimes and extensions that are not used by installed applications, use:

sudo flatpak uninstall --unused

Or:

flatpak --user uninstall --unused

To fix inconsistencies with your local installation, use:

sudo flatpak repair

Or:

flatpak --user repair

Flatpak also has a number of commands to manage the portal permissions of installed apps. To reset all portal permissions for an app, use flatpak permission-reset:

sudo flatpak permission-reset org.gimp.GIMP

Or

flatpak --user permission-reset org.gimp.GIMP

To find out what changes have been made to your Flatpak installation over time, you can take a look at the logs (since 1.2):

flatpak history

However, this requires libsystemd which is not used in void linux.