The Linux community, like any other community, is not particularly good at welcoming new things. Most people want to retain the status quo. In the words of the philosopher Voltaire, the better is the enemy of the good. Nothing is more dangerous than leaving the good for better things.
Systemd, the still controversial system and session manager, illustrates this concept. Other examples are the new package systems Flatpak, Snap, and AppImage, which Linux Magazine previously covered in December 2022. These package systems are by no means met with unanimous approval in the Linux community. In particular, the Snap format, which Canonical initially designed for cloud applications and the Internet of Things (IoT), but later ported for desktop applications, is experiencing opposition beyond the basic criticism of new package systems.
If you've become disillusioned with Snap, the
unsnap script can help you replace snaps with Flatpaks where available on Ubuntu and its deriviatives.
The Linux community is skeptical of any solo efforts by Canonical due to bad past experiences. The main criticisms leveled at Snap (Figure 1) are the Snap Store's proprietary back end and the fact that Canonical is increasingly pushing the format in Ubuntu, with no official way to remove snaps.
The snap daemon (
snapd) is the defined tool for retrieving snaps and all associated metadata from Canonical's servers. In addition, snaps have functional drawbacks that the company has been slow to eliminate. Flatpak, on the other hand, was well received by proponents of alternative package systems. Flatpak is probably the choice of most users outside the Ubuntu environment. This could eventually lead to Canonical mothballing Snap again, as has often been the case in the past with in-house developments such as Ubuntu Touch or the Mir display manager.
This situation has led some distributions to reject or even block snaps. One prominent example is Linux Mint, based on Ubuntu LTS, whose developers decided as early as 2020 not to deliver snaps. They also announced that Linux Mint, starting in version 20, would actively prevent the installation of the Snap framework via the graphical package manager, preventing snaps from automatically ending up on the user's system through the backdoor.
Laptop manufacturers System76 (Pop!_OS) and Tuxedo (Tuxedo OS 1) also avoid shipping snaps with their Ubuntu derivatives. Even Ubuntu users have not rallied behind Snap, as suggested by many guides that describe installing Firefox in Ubuntu as a DEB.
Former Snap co-developer Alan Pope, who left Canonical in 2021 after 10 years with the company, has developed
unsnap, a script that replaces snaps with Flatpaks where available. The script, hosted on GitHub, has been tested by the developers for use on Ubuntu and all derivatives that offer
snapd and packages in the Snap format.
unsnap on a freshly installed Ubuntu 22.04 LTS, I set up a few more packages from the Snap Store in addition to the existing snaps via the Ubuntu Software package manager and then listed them just to be sure (Figure 2). I then downloaded the
unsnap script from GitHub. To do this, I first had to install the <I>git<I> package and then run the command from Listing 1.
Listing 1: Installing unsnap
$ git clone https://github.com/popey/unsnap
Before getting into the nitty gritty, let's take a look at how the script works. Immediately after startup,
unsnap creates a log directory in which it generates six additional scripts tailored to the particular system (see Table 1). The
applist.csv file is used to find Flatpaks that match the installed snaps.
|Runs the snap save command for each Snap package to be migrated.
|Installs the Flatpak package manager if not already done.
|Adds the Flathub repository to Flatpak if not enabled.
|Installs Flatpaks for each identified Snap package, if it exists.
|Removes snaps that have alternative Flatpaks.
|Removes snapd itself, which removes any snaps that are still installed.
To start the script, first change to the appropriate directory by typing
cd unsnap;. The
./unsnap command (Figure 3) first informs you that various checks will be run to determine if Flatpak is already installed and Flathub is included, as well as which snaps have Flatpak equivalents.
unsnap creates the helper scripts. If you have a reason not to run one of the helper scripts, you can launch these scripts manually one after the other. Otherwise, call
./unsnap auto to automatically install the scripts (Figure 4).
On my lab system, I installed about 20 snaps, of which
unsnap was able to replace about half. However, I intentionally installed snaps such as the Canonical Juju and LXD tools, as well as the Mutt command-line email client, to test how the script responded (Figure 5). In general, the chances of finding a Flatpak counterpart for graphical apps are better, because Flatpak targets the desktop. Snap, on the other hand, also targets the server world.
My test took around 10 minutes and provided detailed information about what was happening at all times. The
flatpak list command (Figure 6) can be used to determine which snaps were converted to Flatpak format. For snaps with a Flatpak equivalent,
unsnap converted these snaps cleanly, and all of the programs remained functional. The script left the remaining snaps and the infrastructure untouched. Some manual work would be required to completely oust snaps from the computer.
I then reinstalled Ubuntu 22.04, along with some snaps that I knew had corresponding Flatpaks available, including Gimp 2.99.10 Beta, Krita, Spotify, and KeePassXC. In the process, I also installed several additional runtime environments for Gnome and (because of Krita) KDE, as well as other infrastructure packages from Canonical. With this environment using the same procedure as before, I then tested whether
unsnap also removes the Snap infrastructure when it can convert all snaps to Flatpaks.
I loaded the script and ran it by typing
./unsnap auto. This time,
unsnap first had to install Flatpak and connect to Flathub. After doing so, the call successfully replaced all manually installed snaps with Flatpaks. In addition, it successfully disabled the Firefox snap, which was already present during the install.
When checking via
flatpak list, I noticed one minor disadvantage to this method: All Flatpaks are system-wide and therefore accessible to all users. There is no option to limit the Flatpak to specific users.
Then I ran
snap list to see if there was anything left of the Snap infrastructure. Lo and behold, the snaps had been deleted, but the infrastructure was still there. Apparently, the script did not execute the last of the six helper scripts (
99-remove-snapd). I now did this manually by changing to the
~/unsnap/log2022... directory and running the
./99-remove-snapd command there. The script removes
snapd and takes away the parts of the infrastructure that the base does not need.
However, I discovered the Snap infrastructure is already deeply rooted in Ubuntu and that not everything can be removed even manually (Figure 7).
unsnap, the Snap infrastructure can be removed from the computer. To do this, first disable the corresponding systemd services (Listing 2, lines 1 to 3). Then use the command
sudo snap remove PACKAGE
Listing 2: Removing unsnap
01 $ sudo systemctl disable snapd.service 02 $ sudo systemctl disable snapd.socket 03 $ sudo systemctl disable snapd.seeded.service 04 [...] 05 $ sudo rm -rf /var/cache/snapd 06 $ sudo apt autoremove --purge snapd 07 $ rm -rf ~/snap
to delete everything that
snap list shows you item by item. Last but not least, remove the remnants (lines 5 to 7). Afterwards, the removed packages can be reinstalled manually as DEBs or Flatpaks.
On Ubuntu and its derivatives (if they use Snap),
unsnap lets you swap installed snaps directly for Flatpaks. To do this, an equivalent Flatpak must be available, which is very often the case with graphical applications. With a little manual work, the Snap infrastructure can also be removed.
However, the project warns on GitHub that the software is still at a pre-alpha stage. I attempted to get a statement from Alan Pope, but was unable to do so by the time this issue went to press. I know of many users who have successfully used
unsnap; and I did not experience any problems myself. However, to be on the safe side, I recommend using the manual removal option and then reinstalling the removed packages in your desired format.
This article originally appeared in Linux Magazine and is reprinted here with permission.
Want to read more? Check out the latest edition of Linux Magazine.