How to install specific version of snap?

Although the current answers at https://askubuntu.com/q/1268615/1002900 explain how to install versions of applications which provide channels for specific versions, this isn’t applicable for most, and doesn’t actually answer how to install a specific version of a snap package on a channel instead of how to track a different channel.

I ask because for diagnostic purposes — usually creating bug reports, but also when specific package version is programmatically useful — I need to be able to choose a specific version irrespective of the channels available.

As an example,

snap install powershell --channel=latest/stable

shall currently install 7.4.1, but when that changes, the command no longer installs 7.4.1. This package does not provide versioned channels. How do I force it to forever install 7.4.1?

For comparison, I can install a specific version of a Flatpak package using

flatpak install https://dl.flathub.org/repo/appstream/com.github.Murmele.Gittyup.flatpakref && `
flatpak update app/com.github.Murmele.Gittyup/x86_64/stable --commit=7e1c9370a1a462478b7fac34aac11882cb62768886aa23fe4fd36fb23c17e19b

As a developer of a given snap you can install any of the versions that were ever uploaded to the store.

As a user you can only install a version that is published to a channel, track or branch, but you cannot choose an arbitrary revision.

In practice, if someone wants to offer an experimental build they can use non-stable channel such as edge or beta. If someone wants to offer a feature build it can be done by publishing the snap to a named branch. Any such branch may be used for testing but will automatically close after 30 days IIRC.

EDIT: To expand on my answer. If you need longevity you should requests tracks, so that users may pick the track they want to install from. For instance you may offer track with 7.4 or even 7.4.1.

1 Like

In that case, manually downloading all available versions and applying them using https://askubuntu.com/a/1483150/1002900 might be the sole way to use arbitrary versions as a user.

If you want to you can snap download all the revisions and host them somewhere. It may be useful to host both the .snap and the .assert file and to hold the snap so that it does not refresh.

1 Like

This is actually not quite true any more :slightly_smiling_face:

As of last year, you can install an arbitrary revision, provided it was once released in a public track/channel.

For example:

sudo snap install terraform --classic --revision 605
sudo snap refresh terraform --hold

Will yield you revision 605 installed, and will never refresh. Caution is advised though, because the lack of auto refresh will mean no security/updates at all.

Cheers, Jon

5 Likes

Oh that is indeed news to me! Thank you for the clarification!

2 Likes

@jnsgruk, where is this documented? I’d like to know how to ascertain which version corresponds to which “revision”. (snap info powershell | Select-String 'rev' outputs nothing.)

If you look at the bottom you can see all the revisions for your current architecture:

channels:
  latest/stable:    7.4.1  2024-03-01 (264) 73MB classic
  latest/candidate: ↑                            
  latest/beta:      ↑                            
  latest/edge:      ↑                            
  lts/stable:       7.2.18 2024-01-19 (263) 71MB classic
  lts/candidate:    7.2.8  2022-12-13 (227) 71MB classic
  lts/beta:         7.2.8  2022-12-13 (227) 71MB classic
  lts/edge:         7.2.8  2022-12-13 (227) 71MB classic
1 Like

Oh, the brackets. I didn’t notice. Thank you, @zyga.

1 Like

@zyga, can the channel identifier be combined with the revision? Like

snap install powershell --classic --channel=latest/stable --revision 264

I ask not least because whether revisions are channel-specific is not obvious to me. Could you clarify that too? It doesn’t output any errors, and correctly identifies that that is the version installed.

Revisions are assigned when a blob is uploaded to the store and are not channel specific. You may never publish a revision to any channel or publish the same revision to all the channels.

As for your question, I think that would install that specific revision while tracking latest/stable:

zyga@novigrad:~$ sudo snap install powershell --classic --channel=latest/stable --revision 264
[sudo] hasło użytkownika zyga: 
powershell 7.4.1 from Microsoft PowerShell✓ installed
zyga@novigrad:~$ snap info powershell | grep tracking
tracking:     latest/stable
1 Like