https://ostechnix.com/how-to-install-and-use-flatpak-in-linux/

How To Install And Use Flatpak In Linux


July 1, 2021 12966 Views 4 comments 13

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 applications.

Contents


  1. A Beginners Guide To Flatpak
    1. 1. Add remote repositories
    2. 2. List remotes
    3. 3. Install Flatpak applications
    4. 4. Run Flatpak applications
    5. 5. Search for flatpak applications
    6. 6. List locally installed flatpak applications and runtimes
    7. 7. List remote applications and runtimes
    8. 8. Update flatpak applications
    9. 9. View details of a flatpak application
    10. 10. Uninstall flatpak applications
    11. 11. Remove remote repositories
    12. 12. Remove unused runtimes
    13. 13. Remove flatpak cache
    14. 14. Repair flatpak installation
    15. 15. View flatpak history
    16. 16. Display flatpak help section
  2. Conclusion


Introduction to Flatpak

There are so many Linux distributions and packaging applications for all of those Linux distributions is quite time consuming and difficult task. Even though there are many package converters exists, they all have limited functionality and compatibility issues.

To overcome this problem, an application package format named Snap has been introduced by Canonical. Snaps are initially developed for Ubuntu operating system, but it is now adopted by major Linux distributions including Arch, Gentoo, Fedora, openSUSE etc.

A snap is a single binary package bundled with all required libraries and dependencies. You can install it on any Linux distribution, regardless of its version and architecture. No need to develop 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 we can install multiple versions of the same application at the same time in the Linux system. For instance, it is possible to install VLC player version 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 is 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 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 On 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

There are many popular applications such as Gimp, Kdenlive, Steam, Spotify, and Visual studio code etc., 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

In this section, we will see how to install flatpak apps.

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. Run Flatpak applications

You can launch the installed applications at any time from the application launcher. From command line, you can run it, 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.

5. 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.

6. 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

7. 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

8. Update flatpak applications

To update all your flatpak applications, run:

$ flatpak update

To update a specific application, we do:

$ flatpak update org.gnome.Boxes

9. 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

10. Uninstall flatpak applications

To remove a flatpak application, run:

$ sudo flatpak uninstall org.gnome.Boxes

11. Remove remote repositories

To remove a remote, for example flathub:

$ sudo flatpak remote-delete flathub

Here, flathub is the name of the remote.

12. 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

13. 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.

14. 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

15. 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

16. 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.

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.

Recommended read:

Resources:

  • No labels