Home Package management How To Install And Use Flatpak In Linux

How To Install And Use Flatpak In Linux

A Beginners Guide To Flatpak

By sk
Published: Updated: 23.3K views

In this tutorial, we will see what is Flatpak, how to install Flatpak on Linux and then how to use Flatpak command line user interface to install flatpak applications in Linux.

Introduction to Flatpak

There are so many Linux distributions. Building applications for all of them can be a time consuming and difficult task. Even though many package converters exist, they all have limited functionality and compatibility issues.

To overcome this problem, an application package format named Snap was introduced by Canonical. Snaps were initially developed for the Ubuntu operating system, but they have now been adopted by major Linux distributions including Arch, Gentoo, Fedora, and openSUSE.

A snap is a single binary package bundled with all the required libraries and dependencies. You can install it on any Linux distribution, regardless of its version and architecture. There is no need to develop a separate application for each distribution!

Similar to Snap, there is yet another application package format tool called Flatpak.

Flatpak is a system to build, install, and run applications and runtimes on different Linux distributions.

You can now build a single Flatpak application and install it on different Linux versions. You don't have to worry about the libraries and dependencies; everything is bundled within a single app itself.

Another notable feature is that we can install multiple versions of the same application at the same time on the Linux system. For instance, it is possible to install VLC player versions 2.1, 2.2, and 2.3 on the same system. If you are a developer, you can test different versions of an application at a time.

Flatpak was originally developed by Alex Larsson and later endorsed by Red Hat, Endless Computers, and Collabora. It is now actively maintained by an independent community, made up of contributors, volunteers, and supporting organizations.

The Flatpak framework is written in C and released under the LGPL license.

Runtimes

Each flatpak application depend on a runtime in order to work properly on a host system. A runtime is nothing but a set of basic dependencies (libraries) required by an application.

When we install a application using flatpak command, a runtime will be automatically installed. The runtimes are distribution-independent, so they can work on any Linux distribution. More than one applications can use a single runtime.

There are currently three main runtimes available: Freedesktop, GNOME and KDE. These are all hosted on Flathub repository.

Bundled libraries

The libraries that are not available in a runtime are bundled along with the application by the developers. The libraries can also be the different versions of libraries from the ones that are in a runtime and/or patched versions of libraries.

Sandboxes

A Flaptpak app is built and run in an isolated environment known as "Sandbox". In other words, the flatpak apps are isolated from the rest of the host operating system, and other applications.

Each sandbox contains the application and its runtime. A flatpak application can only access the contents of its sandbox by default. Access to the user files, network, graphics and the devices have to be explicitly given by the user.

Repositories

All flatpak applications and their runtimes are stored in a central place called "Repositories".

Flathub is the official repository of all Flatpak applications. We can access and install the applications and runtimes using flatpak command line interface.

Install Flatpak in Linux

Flatpak is available in the default repositories of popular Linux distributions such as Arch Linux, Debian, Fedora, Gentoo, Red Hat, Linux Mint, openSUSE, Solus, Mageia and Ubuntu distributions.

To install Flatpak on Arch Linux and its variants like EndeavourOS and Manjaro Linux, run:

$ sudo pacman -S flatpak

Flatpak is available in the default repositories of Debian Buster and newer versions. To install Flatpak on Debian, run:

$ sudo apt install flatpak

If you are using GNOME DE on Debian, install the Flatpak plugin for GNOME Software using command:

$ sudo apt install gnome-software-plugin-flatpak

On Fedora, Flatpak is installed by default. All you have to do is enable enable Flathub as described in the next section.

Just in case if it is not installed for any reason, run:

$ sudo dnf install flatpak

On RHEL 7, run:

$ sudo yum install flatpak

On CentOS 7, Flatpak is installed by default. So no setup required!

Starting from Linux Mint 18.3, flatpak is installed by default. So, no setup required.

On openSUSE Tumbleweed, Flatpak can be installed using Zypper:

$ sudo zypper install flatpak

On Ubuntu 18.10 (Cosmic Cuttlefish) and newer Ubuntu versions, install flatpak using this command:

$ sudo apt install flatpak

On older Ubuntu versions, add the following repository and install Flatpak as shown below.

$ sudo add-apt-repository ppa:alexlarsson/flatpak
$ sudo apt update
$ sudo apt install flatpak

The Flatpak plugin for the GNOME Software app makes it possible to install apps without needing the command line. To install this plugin, run:

$ sudo apt install gnome-software-plugin-flatpak

On Solus, install flatpak using command:

$ sudo eopkg install flatpak xdg-desktop-portal-gtk

On Mageia 6 and newer versions, you can install Flatpak with DNF:

$ sudo dnf install flatpak    

Or, install with urpmi, like below:

$ sudo urpmi flatpak

Pop!_OS 20.04 has Flatpak installed and Flathub configured by default. If you are using Pop!_OS 19.10 or earlier versions, run:

$ sudo apt install flatpak

elementary OS 5.1 and newer comes with Flatpak support out of the box.

For other Linux distributions, refer the official installation link.

A Beginners Guide to Flatpak

Many popular applications, such as Gimp, Kdenlive, Steam, Spotify, and Visual studio code etc., are available as flatpaks. To install a flatpak app, we need to first add flatpak repositories (or remotes).

1. Add Remote Repositories

As I mentioned already, the applications and runtimes are stored in a repository or remote. The official repository for flatpak is Flathub.

To enable Flathub repository on Linux, simply run this command:

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

There are many other unofficial flatpak repositories are available. Do a quick web search to find them.

2. List Remotes

To list all configured remote repositories, run:

$ flatpak remotes

Sample output:

Name    Options
flathub system

As you can see, the above command lists the remotes that you have added in your system. It also lists whether the remote has been added per-user or system-wide. In my case, I have added flathub repository system-wide.

3. Install Flatpak Applications

To install a Flatpak application, for example GNOME boxes, run:

$ flatpak install flathub org.gnome.Boxes

The above command will install the application system-wide.

If you don't want to install apps system-wide, you also can install flatpak apps per-user like below.

$ flatpak install --user <name-of-app>

All installed apps will be stored in $HOME/.var/app/ location.

$ ls $HOME/.var/app/
com.github.calo001.fondo com.github.tchx84.Flatseal org.gnome.Boxes

4. Install Multiple Flatpak Applications

To install multiple packages using Flatpak, you can list all the packages you want to install in a single command. Here's the syntax:

flatpak install <app1> <app2> <app3> ...

For example, if you wanted to install two applications, say GIMP and LibreOffice, you would execute:

$ flatpak install org.gimp.GIMP org.libreoffice.LibreOffice

This command would install both GIMP and LibreOffice via Flatpak. You can continue listing more applications separated by spaces if you want to install more than two packages at once.

5. Run Flatpak Applications

You can launch the installed applications at any time from the application launcher. From command line, you can run a flatpak app, for example GNOME boxes, using command:

$ flatpak run org.gnome.Boxes

Flatpak will add the menu entries for all flatpak apps. So you can directly launch the from the menu or application launcher.

6. Search for Flatpak Applications

To search for a application:

$ flatpak search gimp

Sample output:

Name                  Description                                                                                      Application ID               Version Branch Remotes
GNU Image Manipulati… Create images and edit photographs                                                               org.gimp.GIMP                2.10.20 stable flathub
GIMP User Manual      GIMP User Manual                                                                                 org.gimp.GIMP.Manual         2.10    2.10   flathub
Resynthesizer         Set of GIMP plug-ins that heal (in-paint), synthesize texture, theme an image, and more          …p.GIMP.Plugin.Resynthesizer 2.0.3   2-3.36 flathub
GimpLensfun           GimpLensfun is a Gimp plugin to correct lens distortion using the lensfun library and database.  org.gimp.GIMP.Plugin.Lensfun 0.2.4   2-3.36 flathub
Fourier               A simple GIMP plug-in to do fourier transform on your image.                                     org.gimp.GIMP.Plugin.Fourier 0.4.3   2-3.36 flathub
BIMP                  Batch Image Manipulation Program, a GIMP plugin to apply a set of manipulations to an entire gr… org.gimp.GIMP.Plugin.BIMP    2.4     2-3.36 flathub
LiquidRescale         LiquidRescale plugin to resize pictures non uniformly while preserving their features, i.e. avo… …p.GIMP.Plugin.LiquidRescale 0.7.2   2-3.36 flathub
G'MIC                 GREYC's Magic for Image Computing                                                                org.gimp.GIMP.Plugin.GMic    2.9.2   2-3.36 flathub
FocusBlur             Focus Blur plug-in crete a blurring effect similar to Depth of Field.                            ….gimp.GIMP.Plugin.FocusBlur 3.2.6   2-3.36 flathub
Glimpse               Create images and edit photographs                                                               org.glimpse_editor.Glimpse   0.2.0   stable flathub
Scans to PDF          Create small, searchable PDFs from scanned documents                                             com.github.unrud.djpdf       0.1.2   stable flathub

This command will return all applications that matches to the string "gimp" from all remotes.

7. List Locally Installed Flatpak Applications and Runtimes

To view all installed flatpak applications and runtimes on your system, run:

$ flatpak list

Sample output:

Name                           Application ID                  Version Branch Installation
Fondo                          com.github.calo001.fondo        1.3.8   stable system
Flatseal                       com.github.tchx84.Flatseal      1.5.2   stable system
default                        …reedesktop.Platform.GL.default         19.08  system
Intel                          …eedesktop.Platform.VAAPI.Intel         19.08  system
openh264                       ….freedesktop.Platform.openh264 2.1.0   2.0    system
GNOME Boxes                    org.gnome.Boxes                 3.36.6  stable system
GNOME Application Platform ve… org.gnome.Platform                      3.36   system
Ambiance Gtk theme             org.gtk.Gtk3theme.Ambiance              3.22   system
Yaru-light Gtk Theme           org.gtk.Gtk3theme.Yaru-light            3.22   system

If you want to view the list of installed applications and runtimes with installed size, use -d flag.

$ flatpak list -d

Sample output:

… … … Version Branch Arch   Origin  Installation Ref                                               Active commit Latest commit Installed size …
… … … 1.3.9   stable x86_64 flathub system       com.github.calo001.fondo/x86_64/stable            4755529773f0  -              89.3 MB       …
… … … 1.6.2   stable x86_64 flathub system       com.github.tchx84.Flatseal/x86_64/stable          4e1efc03269e  -               2.9 MB       …
…  …         19.08  x86_64 flathub system       org.freedesktop.Platform.GL.default/x86_64/19.08  f68c8e930d04  -             255.7 MB       …
…  …         19.08  x86_64 flathub system       org.freedesktop.Platform.VAAPI.Intel/x86_64/19.08 19fe8e74d641  -              37.0 MB       …
… … … 2.1.0   2.0    x86_64 flathub system       org.freedesktop.Platform.openh264/x86_64/2.0      73f998362a6f  -             778.2 kB       …
… … … 3.36.6  stable x86_64 flathub system       org.gnome.Boxes/x86_64/stable                     98c619ed7873  -             706.9 MB       …
… … …         3.36   x86_64 flathub system       org.gnome.Platform/x86_64/3.36                    d79ff93caf2d  -             934.6 MB       …
… … …         3.22   x86_64 flathub system       org.gtk.Gtk3theme.Ambiance/x86_64/3.22            73fed99df212  -              16.3 MB       …
… … …         3.22   x86_64 flathub system       org.gtk.Gtk3theme.Yaru-light/x86_64/3.22          2573259417d8  -             718.3 kB       …

List only the runtimes with command:

$ flatpak list --runtime

Sample output:

Name                           Application ID                  Version Branch Installation
Locale                         com.github.calo001.fondo.Locale         stable system
default                        …reedesktop.Platform.GL.default         19.08  system
Intel                          …eedesktop.Platform.VAAPI.Intel         19.08  system
openh264                       ….freedesktop.Platform.openh264 2.1.0   2.0    system
Locale                         org.gnome.Boxes.Locale                  stable system
GNOME Application Platform ve… org.gnome.Platform                      3.36   system
Ambiance Gtk theme             org.gtk.Gtk3theme.Ambiance              3.22   system
Yaru-light Gtk Theme           org.gtk.Gtk3theme.Yaru-light            3.22   system

To view only the applications, not run times, use this command instead.

$ flatpak list --app

Sample output:

Name             Application ID                  Version      Branch      Installation
Fondo            com.github.calo001.fondo        1.3.8        stable      system
Flatseal         com.github.tchx84.Flatseal      1.5.2        stable      system
GNOME Boxes      org.gnome.Boxes                 3.36.6       stable      system

To list applications that Use a specific runtime, use:

flatpak list --app --columns=application,runtime | grep "org.freedesktop.Platform"

This command lists the application IDs and the runtimes they use, then filters the output to show only those that mention org.freedesktop.Platform.

8. List Remote Applications and Runtimes

You can also view the list of available applications and runtimes from the remote repositories as well.

To list applications and runtimes from all remotes using command:

$ flatpak remote-ls

List only the runtimes:

$ flatpak remote-ls --runtime

List only the applications:

$ flatpak remote-ls --app

List applications and runtimes from a specific repository, for example flathub, run:

$ flatpak remote-ls flathub

To list only the applications from a remote repository, run:

$ flatpak remote-ls flathub --app

To list applications that use a specific runtime from flathub repository, run:

flatpak remote-ls flathub --app --columns=application,runtime | grep "org.freedesktop.Platform"

9. Update Flatpak Applications

To update all your flatpak applications, run:

$ flatpak update

To update a specific application, we do:

$ flatpak update org.gnome.Boxes

10. View Details of a Flatpak Application

To display the details of a installed application, run:

$ flatpak info org.gnome.Boxes

Sample output:

GNOME Boxes - Simple remote and virtual machines

          ID: org.gnome.Boxes
         Ref: app/org.gnome.Boxes/x86_64/stable
        Arch: x86_64
      Branch: stable
     Version: 3.36.6
     License: LGPL-2.1+
      Origin: flathub
  Collection: org.flathub.Stable
Installation: system
   Installed: 706.9 MB
     Runtime: org.gnome.Platform/x86_64/3.36
         Sdk: org.gnome.Sdk/x86_64/3.36

      Commit: 98c619ed78736e85433bcbecd5c4392ad30d4890a71ddc909f5b4c51dfcde340
      Parent: 72ec972e0ce7fdf640f478d406a8acad5f90ebd1f8c0ac330baa7ed3dd5ccd70
     Subject: Build vte from git master (a8cf05d9)
        Date: 2020-09-02 10:02:20 +0000

11. Uninstall Flatpak Applications

To remove a flatpak application, run:

$ sudo flatpak uninstall org.gnome.Boxes

12. Remove Remote Repositories

To remove a remote, for example flathub:

$ sudo flatpak remote-delete flathub

Here, flathub is the name of the remote.

13. Remove Unused Runtimes

After you removed all applications that depend on a specific runtime, the runtime itself will not be removed automatically.

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

$ flatpak uninstall --unused

14. Remove Flatpak Cache

To remove leftover flatpak cache in the tmp location, run:

$ sudo bash -c "! pgrep -x flatpak && rm -r /var/tmp/flatpak-cache-*"

If you are using systemd as your default system manager, you can automate the flatpak leftover cache cleaning task like below.

Create a service file named clear_flatpak_cache.service in /lib/systemd/system/ directory with the following contents:

[Unit]
Description=Flatpak cache cleaner

[Service]
ExecStart=bash -c "! pgrep -x flatpak && rm -r /var/tmp/flatpak-cache-*"

[Install]
WantedBy=multi-user.target

Start and enable this service at boot:

$ sudo systemctl enable --now clear_flatpak_cache

From now on, the leftover flatpak cache files will be cleared at startup.

15. Repair Flatpak Installation

We can repair a flatpak installation by pruning and reinstalling invalid objects.

To do so, run:

$ flatpak repair

You can also do per-user and per-system repair with --user and --system flags.

Repair per-user installation:

$ flatpak repair --user

Repair per-system installation:

$ flatpak repair --system

16. View Flatpak History

You might have installed some apps, updated them or removed them. All the flatpak transactions will be logged by flatpak.

You can look at these logs to find out what changes have been made to your Flatpak installation over time.

$ flatpak history

17. Display Flatpak Help Section

For flatpak help, run:

$ flatpak --help

This command will display the list of all available flatpak options and sub-commands with a little description.

Additional Tip: List All Uninstalled Flatpak Directories

I came across a script to list all uninstalled Flatpak directories that can safely be removed. Using this script, you can show all unused ~/.var/app directories from uninstalled Flatpaks, and their size.

Create a text file named list-unused-flatpak-directories.sh:

$ nano list-unused-flatpak-directories.sh

Paste the following contents in it:

#!/bin/bash

set -euo pipefail

base_dir=$(realpath $HOME/.var/app --relative-to=$(pwd))

comm -13 <(flatpak list --columns=application | sort) <(ls -1 $HOME/.var/app/ | sort) \
    | sed "s#^#$base_dir/#" | tr '\n' '\0' | du -sch --files0-from=-

Save the file and close it.

Make the script executable using command:

$ chmod +x list-unused-flatpak-directories.sh

Finally, run it to list all uninstalled flatpak directories.

$ ./list-unused-flatpak-directories.sh

Frequently Asked Questions

Flatpak FAQ:

Q: What is Flatpak?

A: Flatpak is an open-source utility that facilitates the distribution of applications across various Linux distributions. It allows developers to build applications once and distribute them across a range of Linux distributions without worrying about compatibility issues.

Q: Who developed Flatpak?

A: Flatpak was originally developed by Alex Larsson and was later endorsed and supported by organizations such as Red Hat, Endless Computers, and Collabora. It is currently maintained by an independent community consisting of contributors, volunteers, and other supporting organizations.

Q: How does Flatpak work?

A: Flatpak allows the bundling of an application along with its necessary libraries and dependencies into a single package. This means that developers do not need to build separate versions of the application for different Linux distributions. Users can install and run Flatpak applications regardless of the distribution they are using, ensuring a uniform experience.

Q: How can I install Flatpak on my Linux system?

A: First, enable Flathub repository:
$ sudo flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
And then install a Flatpak application:
$ flatpak install <name-of-app>

Q: What is the difference between Flatpak and Snap?

A: While both Flatpak and Snap serve the same purpose of streamlining the application distribution process on Linux, they have different approaches and were developed by different organizations. Snap was developed by Canonical, the company behind Ubuntu. Flatpak provides more decentralized application distribution, allowing for multiple repositories, whereas Snap mainly operates from a centralized repository.

Q: Can I install multiple versions of an application using Flatpak?

A: Yes, one of the notable features of Flatpak is the ability to install and run multiple versions of the same application concurrently. This is particularly useful for developers who might need to test different versions of an application at the same time.

Q: How does Flatpak ensure application security?

A: Flatpak emphasizes security by isolating applications from each other and the core system using technologies like namespaces and seccomp. This means that applications have limited access to the host system, reducing the risk of system-wide compromise.

Q: What programming language is Flatpak written in?

A: Flatpak is primarily written in the C programming language. It is released under the LGPL (Lesser General Public License)

Conclusion

This flatpak tutorial gave you a brief introduction to Flatpak, and the underlying technologies used in Flatpak such as runtimes, remotes, bundled libraries, and sandboxes etc. And then, It also explained how to install and use flatpak on Linux distributions.

Resources:

You May Also Like

4 comments

Franco July 2, 2021 - 2:17 am

Useful tutorial. Thanks.

Reply
James July 4, 2021 - 4:13 pm

Flatpak, Snap, Appimage. A lot of choice, but which is right for you? I love choice, but Is Linux wasting resources re-inventing the same wheel? Will there ever be a universal Linux package?

Reply
sk July 4, 2021 - 6:38 pm

They are invented to use universal package format on multiple distributions. We have published a detailed comparison of Flatpak, Snap and AppImage here -> https://ostechnix.com/linux-package-managers-compared-appimage-vs-snap-vs-flatpak/

Reply
James July 6, 2021 - 3:13 pm

Thanks for the info SK.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More