Swap snaps for Flatpaks with unsnap

Rework Needed

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.

Figure 6: After running unsnap, the flatpak list command can be used to check which snaps the script replaced with Flatpaks.

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

Figure 7: I had to follow up with the ./99-remove-snapd script to remove as much of the Snap infrastructure as possible. Nevertheless, some remnants remained.

Manual

Even without 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

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
sudo snap remove PACKAGE

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.

Conclusions

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.

Infos

  1. "Innovative Linux Package Managers" by Erik Bärwaldt, Linux Magazine, issue 265, December 2022, p. 72
  2. Snap Store: https://snapcraft.io/store
  3. Mint without Snap: https://linuxnews.de/2020/06/02/linux-mint-20-ohne-snapd/
  4. unsnap: https://github.com/popey/unsnap
  5. applist-csv: https://github.com/popey/unsnap/blob/main/applist.csv

The Author

Ferdinand Thommes lives and works as a Linux developer, freelance writer, and tour guide in Berlin.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News