Introduction

With the use of modern Gnu/Linux distributions package managers, package dependencies are no more a problem per-se, but usually each distribution ships with a certain version of a program, and we want to install a new version we have to compile it, or rely on third party repositories. The same thing happens if the repositories of our favorite distribution doesn't contain a certain application we need. Also for an application distributor can be time-consuming having to provide different package formats for the same application.

Flatpak is a relatively new technology which aims at solving those kind of problems. Applications installed with Flatpack come pre-packaged with all their dependencies and run in their own sandboxed environment. In this tutorial we will see how to install and use flatpak on Fedora 28.

Using Flatpak

Fedora Workstation comes with flatpack pre-installed, therefore we already have all we need in our system. Flatpak applications can be installed both globally, by running the command with administrative privileges, or per-user. In the latter case the applications will be installed inside the user's home directory: we will use this option in this tutorial.

Add a flatpak repository

Before using flatpack we must enable a package source. In this case we are going to use flathub: this repository hosts a lot of common used applications, both open-source and proprietary. For the sake of this guide we will install the flatpak version of the atom text editor. First thing to do is to enable the flathub repository:
$ flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
Let's briefly analyze the command above. The first option we used is --user, basically saying that the command must be executed in the user context, and not globally. To add the remote repository we used the remote-add command followed by the --if-not-exists option, which serves as a check to verify that the remote repository has not already be added. Finally, we passed the name of the repository and its location. The latter can be either the url of the repository, or a .flatpakrepo file, which containing a repository description. To verify that the repository has been added, we can run:
$ flatpak remotes
In this case, the above command will return the following output, showing us that the repository has been successfully added to our sources:
Name Options
flathub user

List the content of a repository and search for a package

Let's see what the repository we just added contains. To list the content of a repository, all we need to do is to run the following linux command:
$ flatpak remote-ls flathub
The command will return a list of the available applications and runtimes. Among the others:
[...]
io.atom.Atom
io.atom.electron.BaseApp
io.elementary.code
io.exodus.Exodus
io.github.Cockatrice.cockatrice
io.github.EndlessSky.endless-sky
io.github.FreeDM
io.github.Freedoom-Phase-1
io.github.Freedoom-Phase-2
io.github.GnomeMpv
io.github.Hexchat
[...]
Retrieving further information about a package it's just as easy. Say for example we want to examine the io.atom.Atom package, all we need to run is:
$ flatpak remote-info flathub io.atom.Atom
The following output will be displayed:
Ref: app/io.atom.Atom/x86_64/stable
ID: io.atom.Atom
Arch: x86_64
Branch: stable
Date: 2018-04-22 00:56:36 +0000
Subject: Update to 1.26.0 (3b4ae17a)
Commit: 7738413d8dc76121224c42af8c10925198f6628204bbc12f1f1fceb3ccde5c7b
Parent: eb8acc77b2408e4352a88015aa317a7f2b5781cc47dc593d48f707ef1c13d3ed
Download size: 155.9 MB
Installed size: 560.8 MB
Runtime: org.freedesktop.Sdk/x86_64/1.6
If instead we want to search for a specific package, we should run:
$ flatpak --user update && flatpak --user search atom
Looking for updates...
Updating appstream data for user remote flathub
Application ID         Version Branch Remotes Description
net.sourceforge.atanks         stable flathub Turn-based artillery strategy game
io.atom.Atom           1.26.0  stable flathub A hackable text editor for the 21st Century
com.github.rssguard            stable flathub Simple (yet powerful) feed reader
The command updates applications and runtimes, than actually searches for the package. The update part is necessary and has to be executed at least the first time we perform a search, otherwise no matches will be returned.

Installing a package

Let's get to the point. We now will install the io.atom.Atom package in our system. From what we can see in the package information, the downloaded size will be 155.9 MB and application will occupy 560.8 MB of disk space once installed:
$ flatpak --user install flathub io.atom.Atom
Required runtime for io.atom.Atom/x86_64/stable (org.freedesktop.Sdk/x86_64/1.6) is not installed, searching...
Found in remote flathub, do you want to install it? [y/n]:
The package requires the org.freedesktop.Sdk/x86_64/1.6 runtime: Flatpak searched for it in the flathub repository and once founded, it asked our confirmation to retrieve it. As soon as we provide it, the installation begins:
Installing for user: org.freedesktop.Sdk/x86_64/1.6 from flathub
[####################] 17 delta parts, 144 loose fetched; 274723 KiB transferred in 47 secon
Installing for user: org.freedesktop.Platform.VAAPI.Intel/x86_64/1.6 from flathub
[####################] 1 delta parts, 2 loose fetched; 2623 KiB transferred in 1 seconds
Installing for user: org.freedesktop.Platform.ffmpeg/x86_64/1.6 from flathub
[####################] 1 delta parts, 2 loose fetched; 2652 KiB transferred in 2 seconds
Installing for user: org.freedesktop.Sdk.Locale/x86_64/1.6 from flathub
[####################] 4 metadata, 1 content objects fetched; 14 KiB transferred in 1 second
Installing for user: io.atom.Atom/x86_64/stable from flathub
[####################] 2 delta parts, 36 loose fetched; 141132 KiB transferred in 30 seconds
Done! The package has been installed and it's usable just as it was installed normally.

List and remove installed packages

Another common operation we would like to perform, is to list all the applications installed via flapak. Nothing simpler:
$ flatpak list
In our case this will just return:
Ref                                             Options
io.atom.Atom/x86_64/stable                      user,current
org.freedesktop.Platform.VAAPI.Intel/x86_64/1.6 user,runtime
org.freedesktop.Platform.ffmpeg/x86_64/1.6      user,runtime
org.freedesktop.Sdk/x86_64/1.6                  user,runtime
As you can see the atom package and the runtime installed to be able to run it, are correctly displayed. Removing a package it's just as easy:
$ flatpak --user uninstall io.atom.Atom
Uninstalling: io.atom.Atom/x86_64/stable
If we now get again a list of the installed package, we can see that io.atom.Atom is no more installed:
Ref                                             Options
org.freedesktop.Platform.VAAPI.Intel/x86_64/1.6 user,runtime
org.freedesktop.Platform.ffmpeg/x86_64/1.6      user,runtime
org.freedesktop.Sdk/x86_64/1.6                  user,runtime
Unfortunately, as you can see, while the main package has been uninstalled, its dependencies are already present, because they are not automatically removed. You may expect a command like dnf autoremove to be available, in order to remove orphaned, no more needed dependencies. Unfortunately, at the moment of writing, this has not been implemented yet. It would be very useful, since flatpak applications can occupy a lot of space in the system. A feature request already exists on the github page of the project; in the meanwhile, dependencies must be removed manually when sure that no other package needs them.

Conclusions

We saw what flatpak technology is, and how, although still young and improving, it can be a nice and safe solution to obtain applications not available by default in a distribution repositories. We saw how to add a flatpak repository, how to inspect it, and how to search, install, remove and update a package. We performed those actions from command line interface, to have a better understanding of how flatpak works under the hood; however packages and repositories can be installed also graphically, running the GNOME Software application and browsing the flathub website.