Can I install a package using its `snap-id`?

For instance, can I install Install powershell on Linux | Snap Store using JSNnoJl3EqkMuWoy5Dgq8PMqZ0uNcpie? I ask because I would like my automation scripts to be resilient to name changes. After all, there’s a good reason that internally the snap-id is used rather than the name.

Ironically, the snap name cannot change but the snap ID can (though usually never does either).

There’s no renaming of snaps, there’s only creating a new snap and encouraging people to use the new one. Because of this unfortunately I think there’s no way to automate the situation a snap author starts publishing to a new name; although I’d agree it’d make sense to add in the future; as a snap publisher who has to keep publishing some of my snaps twice until people eventually stop using the old one!

That said, it also makes sense to not let snaps do this, because if E.G you have a snap being used in a script, and suddenly that snap changes name to a completely different name, that script will just break even if snapd itself handles the migration gracefully, which means whilst it might fix installing things primarily handled as desktop apps via the start menu, it’s useless for things that would be used via CLI.

(And super unfortunately speaking from experience, it’s incredibly easy to accidentally hardcode variables under the old name that would also break if the directory layout was rewritten, so ultimately I think there’s a significant amount of technical complexity in allowing this even if it would be nice to have in theory).

They can not, the ID is actually as unique as the name (and as permanent), it is used everywhere except in the snap cli tool itself (i.e. model assertions when you build UbuntuCore images, settings and connections in gadget.yaml etc)

Technically you might be able to use REST API calls from some script to actually achieve installation by ID, but not from “snap install…” itself.

1 Like

You might be interested in Install what-snap on Linux | Snap Store

$ what-snap JSNnoJl3EqkMuWoy5Dgq8PMqZ0uNcpie
JSNnoJl3EqkMuWoy5Dgq8PMqZ0uNcpie: powershell
$ echo snap install $(what-snap JSNnoJl3EqkMuWoy5Dgq8PMqZ0uNcpie | awk '{print $2}')
snap install powershell
2 Likes

I believe that’s the case from the user side, but there was a situation a few years ago I recall where having the snap ID forcibly changed was proposed as a viable option.

The exact scenario was where a different author was taking over the name of a registered snap, but the applications weren’t the same app at all, they just shared names. Swapping the Snap ID was proposed as an option to prevent older users suddenly finding their snap updated to a completely different application.

I’ll take a look around to try find the exact discussion, but ultimately for all practical purposes (and probably in all instances to date), yes, the ID won’t change.

1 Like

Ah, well, that case back then would have been equivalent to removing the snap and re-adding it from a new author… in that case the first new upload will indeed generate a new ID since it will be handled like a new snap… i think the same happens if a user abandoned a snap, filed a removal request (which disallows this user to ever own this snap again) and a new user registers the same named snap anew…

1 Like

Thanks all. I’ve asked the same about Flathub at https://discourse.flathub.org/t/does-flathub-use-an-internal-id-in-case-packages-are-renamed/6169, if of interest.