With so many Linux distributions available, it is hard to deploy applications to them. This is due to the fact that you might face problems while trying to reproduce bugs and issues reported by users that are working on the application on different distributions. So you find that the application can function well on one Linux distribution and not on another and probably leading to either integrating the application with different dependencies or building the application differently from how you envisioned it in the first place. For a developer, this is frustrating and time-consuming at the same time. To combat this Flatpak was created to change the distribution applications in different Linux platforms for the better.
Flatpak uses container technology so that your application runs the same way on all Linux-based platforms. This makes it simple to develop and deploy your application reducing time wastage which you can spend on other productive activities. You also have the option of being in control of the application updates that ensure users make use of the updates as they come. Flatpak hosts hundreds of applications on the Flathub repository where you can check them out and find an application that you want to use. It is an independent project developed by an independent community with no lock-in to a single vendor.
Another benefit that comes with Flatpak includes a Foward-compatibility feature that allows the same application to be run on different versions on different distributions. You can ship almost any library and dependency that the Flatpak application requires to run as part of it by bundling them together. Developers can also ship applications from different branches without changing their names. Flatpak also integrates with the desktop to enable users to easily browse, install, run and use Flatpak applications through their existing desktop environment and tools.
Flatpak features include:
- Applications developed are distributed across all Linux platforms.
- Developers and users use a consistent environment.
- Flatpak tools are simple and easy to use for building applications.
- Improved application distribution to a larger audience due to compatibility.
- Stable platform with common libraries that you can depend on.
- Allow you to bundle your application libraries as your own.
- The applications are future-proof use even with new Linux distributions.
Reasons to use Flatpak:
There is an extent to which the current model of packaging has some issues and that is why Flatpack is highly recommended for use. This ranges from different package managers contained in different Linux platform that contains different packages with different formats. This leads to having a lot of hand on while maintaining and updating these packages. With that, let us take a look at the reasons why Flatpak is available to use.
- Universality that comes with Flatpak as applications are installed and run on almost any Linux-based Platform.
- Saves time as developers only get to maintain one application and hence focus on other innovations.
- As Flatpak applications do not depend on the host, if an application crashes, it does not interfere with the system.
- You can install Flatpak applications without root privileges.
- Secure as applications are developed in a sandbox that is isolated from the host environment.
- Flatpak allows decentralized hosting and distribution so that application developers can host their own applications and application repositories.
- Space efficient as Flatpak replicates libraries to be used by multiple applications.
- Delta Updates as only the files that are changed are updated.
Flatpak basic concepts that assist you in understanding how to use Flatpak from the command line or using it to build applications.
- The Operating system is basically the Linux Kernel.
- Runtime contains the basic dependencies and libraries that are used by applications. It should be installed in your system before you use Flatpak to run an application. An advantage to runtimes is that they do not depend on particular distribution versions which allow applications to continue to work irrespective of operating system updates.
- The Bundled libraries contain the dependencies that an application would want to run but are not available on their own runtime which gives the application developers flexibility to bundle libraries as part of the application.
- Each application is built in an isolated environment called a sandbox that contains the application and its runtime and they cannot possibly access the host processes and resources just like that.
- Portals allow applications inside a sandbox to interact with the host environment data, files and services without the need to add sandbox permissions.
- A Flatpak repository that typically stores and publishes Flatpak applications.
In this guide, we are going to look at how to manage Flatpak applications in Linux.
Install Flatpak on Linux
Flatpak can be installed and used on almost any Linux distribution. To install on common Linux-based distributions, use the commands below:
## Debian-Based Distribution ##
sudo apt install flatpak
sudo apt install gnome-software-plugin-flatpak
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
## RHEL-Based Distribution ##
sudo yum install flatpak
## Arch-Based Distribution ##
sudo pacman -S flatpak
## openSUSE ##
sudo zypper install flatpak
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
To complete the setup, restart your system to be able to install applications. You can also confirm successful installation by checking teh version.
$ flatpak --version
Flatpak 1.12.9
Basic Flatpak Commands
1. Manage Flatpak repositories
To add a remote repository, run the following command:
flatpak remote-add [OPTION…] NAME LOCATION
##For Example, adding the flathub repo
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
To list the remote repositories that have been configured on your system, run the following command.
$ flatpak remotes
Name Options
flathub system
To show and print general information about a local repository.
flatpak repo --info
To list and show repositories with the default system-wide configuration
flatpak remotes --system
To list repositories with a system-wide installation by specifying a NAME:
flatpak remotes --installation=default
To show available runtimes and applications on a remote repository:
flatpak remote-ls <repo-name>
To show more information for each repository in addition to the name.
flatpak remotes --show-details <repo-name>
To add a remote repository:
flatpak remote-add <repo-name>
To modify a repository:
flatpak remote-modify <repo-name>
To remove a remote repository, run the following command
flatpak remote-delete <repo-name>
2. Search for Flatpak applications
To search for applications and runtimes, use the search query as shown.
flatpak search
Let us say I am looking for an application named gimp, the command to run would be as follows.
flatpak search gimp
To search and show results of a system-wide installation specified by name:
flatpak --installation=default search gimp
3. Install Applications with Flatpak
To install applications use the following command syntax.
flatpak install
So let’s say I want to install the gimp application, I would run the command as sown below:
flatpak install flathub org.gimp.GIMP
Here, flathub is the name of the remote the application to be installed from, and org.gimp.GIMP is the ID of the application.
Other than that, details of the application to be installed can also be provided by a .flatpakref file, which is kind of a reference file that can be remote or local. If you do not want to provide the remote and application ID, you can specify a .flatpakref instead.
flatpak install https://flathub.org/repo/appstream/org.gimp.GIMP.flatpakref
If the application is to be installed from a remote that is not added, you will be prompted to add it locally. But with the major improvements since Flatpak 1.2 a simple command to run an install below will do just fine.
flatpak install gimp
To install the application or runtime in a per-user installation:
flatpak --user install flathub org.gimp.GIMP
To install the application or runtime in a system-wide installation specified with NAME:
flatpak --installation=default install flathub org.gimp.GIMP
To show information about an installed application or runtime
flatpak info org.gimp.GIMP
4. Running Flatpak Applications
Once the application has been installed, run it with the application ID as shown below.
flatpak run org.gimp.GIMP
To run an application and runtime in the default system-wide installations:
flatpak run --system org.gimp.GIMP
To run a different command like BASH instead of the one listed in the application metadata:
flatpak run --command=bash org.gimp.GIMP
To run an application and runtime in per-user installations: This will look at the installations of the current user.
flatpak run --user org.gimp.GIMP
To use a different branch:
flapak run --branch=BRANCH org.gimp.GIMP
5. Updating Flatpak Applications
To update all Flatpak applications, run the following command.
flatpak update org.gimp.GIMP
To update applications with the default system-wide installation:
flatpak --system update org.gimp.GIMP
To update applications with the system-wide installation specified by NAME.
flatpak --installation=default update org.gimp.GIMP
To update the application as per user installation.
flatpak --user update org.gimp.GIMP
6. List installed Flatpak applications
To list applications and runtimes that you have installed:
flatpak list
To just list the applications only:
flatpak list --app
To just list the runtimes only:
flatpak list --runtime
To list applications and runtimes as per-user installation:
flatpak --user list
To list applications and runtimes with system-wide installations:
flatpak --system list
To list applications and runtimes as per system-wide installed specified by NAME:
flatpak --installation=default list
7. Uninstall Flatpack Applications
To uninstall applications, run the following command
flatpak uninstall org.gimp.GIMP
To only uninstall an application:
flatpak --app uninstall org.gimp.GIMP
To remove the runtime only:
flatpak --runtime uninstall org.gimp.GIMP
To uninstall from per-user installations:
flatpak --user uninstall org.gimp.GIMP
To uninstall from the default system-wide installation:
flatpak --system uninstall org.gimp.GIMP
To uninstall from the default system-wide installation specified by NAME:
flatpak --installation=default uninstall org.gimp.GIMP
To remove runtimes and extensions that are not used by installed applications:
flatpak unistall --unused
8. Stop/Kill Flatpak Applications
Use the following command to find out the IDs of the running Flatpak applications.
flatpak ps
To stop or kill an instance of an application
flatpak kill org.gimp.GIMP
To override an application-specified runtime requirements
flatpak override org.gimp.GIMP
To override an application with a context section from the application metadata by looking at the subset of the filesystem:
flatpak override --filesystem=home org.gimp.GIMP
9. Managing Flatpak Application File Access
To export a file to a sandboxed application:
flatpak document-export --app=org.gimp.GIMP ~/test.txt
To stop exporting the file: This removes the document id for the file from the document portal:
flatpak document-unexport
To show information about specific exported files:
flatpak document-info
To list all the exported files.
flatpak documents
To copy apps and/or runtimes onto removable media.
flatpak create-usb
10. Manage Installed Flatpak Applications
To show changes to the Flatpak installations on the system:
flatpak history
To enter an application or runtime running sandbox:
flatpak enter
If your system does not support unprivileged user namespace, run it as below.
sudo -E flatpak enter
To modify the configuration of a Flatpak installation:
flatpak config
To repair a Flatpak installation by either pruning or reinstalling invalid objects. The command has to be run with root privileges.
sudo flatpak repair
To repair an installation as per-user installation:
flatpak repair --user
To list dynamic permissions which are stored in the Flatpak permission store:
flatpak permissions
To list dynamic permissions for a given application which are stored in the Flatpak permission store.
flatpak permission-show
To remove all permissions for the given app from the Flatpak permission store.
flatpak permission-reset
To set the permissions for an application in an entry in the permission store.
flatpak permission-set
Conclusion
Flatpak makes it easy to install and manage applications on your platform without having to look for extra libraries and dependencies. Updating from the local or remote repository is also easy as they are both available. It also makes it for developers to just build one application that can be deployed on all Linux platforms as the applications run in an isolated environment (sandbox) that does not depend on nor interfere with the host resources.
Check out more articles: