I’d like to pin a specific package, say redis-server
, to a specific version, in my case 7.0.*
, and that seems straight-forward to do with:
Package: redis-server
Pin: version 7.0.*
Pin-Priority: 1001
Now, I would also like to have apt
fail when 7.0.* is not available, either because there are only newer versions available, f.ex. 7.2.* or 7.4.* or perhaps because only older versions like 6.* are available.
I can’t seem to find a way to achieve that. I’ve read various resources only, consulted man 5 apt_preferences
, but I’m still not sure how to.
I tried combining the previous pinning rule to another one with priority -1
, as in the following:
Package: redis-server
Pin: release *
Pin-Priority: -1
But that seems to make all versions unavailable unfortunately. Here’s what I’m seeing:
$ apt-cache policy redis-server
redis-server:
Installed: (none)
Candidate: 5:7.0.15-1build2
Version table:
5:7.0.15-1build2 500
500 [http://no.archive.ubuntu.com/ubuntu](http://no.archive.ubuntu.com/ubuntu) noble/universe amd64 Packages
$ cat > /etc/apt/preferences.d/redis-server
Package: redis-server
Pin: version 7.0.15*
Pin-Priority: 1001
Package: redis-server
Pin: release *
Pin-Priority: -1
$ apt-cache policy redis-server
redis-server:
Installed: (none)
Candidate: (none)
Version table:
5:7.0.15-1build2 -1
500 [http://no.archive.ubuntu.com/ubuntu](http://no.archive.ubuntu.com/ubuntu) noble/universe amd64 Packages
I expected this configuration to provide an available candidate, since one exists (7.0.15), but that doesn’t work.
Note that a successful outcome for me is:
- define a target wanted version, f.ex.
redis-server=7.0.*
- provide an apt preferences.d file such that:
- when any 7.0.* versions are available, apt will install that version
- when no 7.0.* versions are available, apt will fail installing nothing
A bad outcome is when redis-server is installed, but with a package version that does not match what I had specified as requirement (hence, different from 7.0.*).
This is on Ubuntu 24.04, although there is nothing specific to 24.04 or Ubuntu here I would think.
Any ideas?
Posted on stackoverflow, let’s see! https://unix.stackexchange.com/questions/790837/how-to-pin-an-apt-package-to-a-version-and-fail-if-its-not-available
UPDATE: based on the stackoverflow feedback, it seems that the solution wasn’t far off.
Package: redis-server
Pin: version 5:7.0.15*
Pin-Priority: 1001
Package: redis-server
Pin: release *
Pin-Priority: -1
I needed to prepend the version with the "5:
“.