How to avoid installing package twice?


Is there any way to prevent installing a snap package if some specific non-snap package is already installed on a system?

Detailed description: Our software can be installed out from the standard package (deb/rpm) and out from the snapped package. But I want to avoid situations when users install software twice (from deb and from snap).

This is an interesting question. It might be worth experimenting with the snapcraft install hook.

This hook is invoked when the snap is first installed on the system. You could try to use this hook to check if the system already has the .deb package already installed. However, due to snap confinement, you might need to experiment with using different interfaces in your snap package. Here are some resources that could help with setting up the install hook for the snap package:

For Debian packages, you can use a pre-install script alongside your control file. You could use some fancy shell control statement. You can use snap list <your-package-name> to check if snap is installed on the system and then use awk to parse the output. I found this YouTube video to be helpful for working with preinstall hooks in Debian packages:

Let me know how this goes as I am interested in this topic as well!

I will try to play with the install hook for the snap package.

Regarding deb/rpm packages…
I already implemented the mechanism you mentioned (pre-install scriplet). It works well:

snap list <pkg_name> > /dev/null 2>&1 && echo "[!] INSTALLATION CANCELED: The snap package '<pkg_name>' is already installed. Please, uninstall the '<pkg_name>' snap package first." && exit 1

1 Like

Awesome. I am going to save this snippet since I need it for some packages too. Thanks!