Flatpak has gained popularity among Linux users and developers due to its potential to simplify software distribution, increase security, and provide a consistent application experience across different Linux distributions.
Let me give you an example. Sometimes you may need a newer version of an application that is unavailable in the repositories of your distribution. Or even the application itself is not available there.
But even if you find a package of this software available somewhere for the package manager used by your system, you may not be able to install it. Why?
Because for example, the latest version of that program requires different versions of the system libraries than you have, and here is where Flatpak comes into play.
What Is Flatpak?
Flatpak is a package management and software distribution system for Linux-based operating systems. It allows users to install applications in an isolated sandbox environment decoupled from the underlying operating system.
It is designed to provide a consistent and secure way to package, distribute, and run applications across different Linux distributions, regardless of their underlying libraries and dependencies.
As a result, it is a universal package management system to build, install, and run applications on different Linux distributions.
How Ftlatpak Works?
Each Flatpak application depends on runtime to work appropriately on a host system and comes bundled with all dependent libraries inside the app. A runtime is a set of basic dependencies (libraries) an application requires. The most commonly used ones are Freedesktop, GNOME, and KDE.
One of the significant advantages of the Flatpak is that libraries are reused as needed, so they are not installed for every package.
For example, the Dolphin file manager would be equivalent in size if you installed it on an entirely new system, whether you use the Flatpak or the systemโs native package manager.
However, if you install it as a Flatpak application since the required Qt libraries will be available on the system, the next Qt application you install that uses Qt will take up significantly less space.
At the same time, you need to keep something else in mind. If you have to use Flatpaks extensively, you can expect to have a lot of duplicated runtimes because many applications use different versions of those runtimes. In other words, the dependencies are still reused, but only when possible.
Installing Flatpak on Linux
Flatpak installation is a two-step procedure. First, to use Flatpak packages, your Linux distro must have Flatpak support.
The most recent versions of some Linux distros, such as Fedora, Linux Mint, elementaryOS, Zorin OS, etc., come with Flatpak support out-of-the-box. In other words, there is no need to install such support on them.
The easiest way to check if you have Flatpak installed is by running, for example:
flatpak list
Code language: PHP (php)
If you receive command output similar to the one shown above, all is well, and your system has the necessary Flatpak support.
However, if you get a message like the one below, “Command ‘flatpak’ not foundโฆ” you can easily install it depending on the Linux distribution you are using with any of the below-provided commands.
Install Flatpak on Ubuntu, Debian, and Pop!_OS
sudo apt install flatpak
Install Flatpak on AlmaLinux, Rocky Linux, CentOS, and RHEL
sudo dnf install flatpak
Install Flatpak on Arch Linux and Manjaro
sudo pacman -S flatpak
Install Flatpak on openSUSE
sudo zypper install flatpak
For all other Linux distributions, you can check here.
How to Install Flatpak App
Once you finish installing the flatpak
package, you are ready to install Flatpak applications. But before you do that, let’s get aware of the central Flatpak repository – Flathub (https://flathub.org).
To enable the Flathub repository to allow you to install applications from there, type the command below:
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
Code language: JavaScript (javascript)
Search for Flatpak Apps
Once the repository is added, you can check if a particular application is available. So you can treat Flatpak as a regular package manager.
You can search for a Flatpak app by using the flatpak search
command. For example, letโs search for Spotify:
flatpak search spotify
The output gives you details about the Flatpak application, such as the Application ID, version, branch, and application summary.
Install a Flatpak App
The basic syntax to install applications using Flatpak is flatpak install applicationID
. So, the command to install Spotify will be:
flatpak install com.spotify.Client
Code language: CSS (css)
Install a Specific Flatpak App Version
Although it is not common practice, you may need to get a specific version of an app rather than the latest version installed by default when installing a Flatpak package.
Weโll use the Spotify (com.spotify.Client) Flatpak package as an example to demonstrate. The command below displays all available versions for installation; the identifier you will use for installation is the line “Commit.”
flatpak remote-info --log flathub com.spotify.Client
Code language: CSS (css)
So, if we want to install, say, the penultimate version available, the command to use is:
flatpak update --commit=60f1d52b28a0119214e9f68401de94593ffd26dbf3c77f7402582e3f274e2fa8 com.spotify.Client
It’s worth noting that because we’re using the update
option, you must already have installed the Flatpak package before you can downgrade to an older version.
Run a Flatpak App
Running a Flatpak is quite simple. For example, in our case, here is what the command will look like:
flatpak run com.spotify.Client
Code language: CSS (css)
Of course, you can run the app like any other from the App Launcher you use.
List Installed Flatpak Apps
You can list all the currently installed Flatpak apps by running the command shown below:
flatpak list
Code language: PHP (php)
Update Installed Flatpak Apps
To update Flatpak packages within your system, run the following:
flatpak update
Keep in mind that if all packages are already up to date, there will be no new changes after running the above command.
Uninstall a Flatpak App
Finally, removing it is quite a simple operation if you no longer need the Flatpak application. The syntax of the command is flatpak uninstall applicationID
.
For example, to remove Spotify, execute the command:
flatpak uninstall com.spotify.Client
Code language: CSS (css)
We should also mention one feature. When you uninstall a Flatpak application, the user data for that app is retained on your system. They are usually saved in “~/.var/app.”
To remove this data during uninstallation, use the --delete-data
option. As a result, the above command would look like this:
flatpak uninstall --delete-data com.spotify.Client
Code language: CSS (css)
Removing Unused Flatpak Runtimes
It is a good practice to clean your system and free up space occasionally. You can remove the unused Flatpak runtimes by using the command shown below:
flatpak uninstall --unused
Flatpak: Pros & Cons
Without a doubt, Flatpak has revolutionized package management in Linux. But like any other technology, this one has good and not-so-good sides. So, letโs summarize them.
Pros
- Distro-agnostic: You can install Flatpak packages on any distro you want. In other words, you can create one app and distribute it to the entire Linux desktop market.
- Application sandboxing: All applications are limited to predefined permissions, enhancing privacy and security.
- Up-to-date package versions: The Flatpak packages on flathub.org can be more up-to-date than the various Linux distributions offered in their repositories.
- OS safety: Because none of your system libraries are upgraded, you do not risk instability or problems with your other programs or operating system.
- Easy to use: Offers easy integration with an existing software center on your Linux distribution.
Cons
- “Bloated” than native apps: Many Flatpak packages have dependencies, which tend to be gigantic. For example, a simple Calculator app can take up more than 300+ MB of storage space.
- Memory usage: Each app with a new runtime adds another hundred megabytes or more RAM usage.
- Speed: The Flatpak apps have to load all their libraries from disk instead of using whatโs already on the system or in memory. This slows down the time they need to get started. Of course, once running, they should not be slower than regular packages.
Conclusion
Flatpak is a powerful tool that allows Linux users to easily install and run applications in a secure and sandboxed environment.
With its cross-distribution compatibility and simplified packaging process, Flatpak has gained popularity in the Linux community as a way to distribute and manage software eliminating version conflicts.
Moreover, itโs good when you want to use applications not in your distribution repository or require a newer version of an application.
In this comprehensive guide, we have explored the basics of Flatpak, including how to install it, set up repositories, search and install applications, and manage updates.
For additional help or useful information, check the official Flatpak documentation.
Feel free to express your opinion or ask questions in the comments below.