Running the apt-cache policy command shows which candidate for an application is available for installation.
Using the Audacity software package as an example, run the following command in your terminal:
apt-cache policy audacity
The output will reveal which candidate is available for installation.
audacity:
Installed: (none)
Candidate: 2.3.3-1build1
Version table:
2.3.3-1build1 500
500 http://archive.myasnchisdf.eu.org/ubuntu focal/universe amd64 Packages
If the Audacity package has been blocked, the candidate version number would be replaced with (none)
. Blocking Audacity requires updates to apt preferences.
Where to define apt preferences
The apt preferences file /etc/apt/preferences
and the fragment files in the /etc/apt/preferences.d/
folder can be used to control which versions of packages will be selected for installation. Fragment files should be defined with the .pref
suffix. By default, the apt preferences file at /etc/apt/preferences
will be empty, and the /etc/apt/preferences.d/
folder will be empty as well.
The manpage states the apt preferences file is where you would specify pinning: the preference to get certain packages from a different source, or a different version of a distribution. Apt preferences fragment files are where version preferences for applications can be defined. Blocking packages can be achieved through modifications of either the apt preferences file or through fragment files. The same configuration can be applied in both locations, and achieves the identical end result of blocking an application’s installation.
How to define apt preferences fragment files
While there are many ways to organise your apt preferences fragment files in the /etc/apt/preferences
directory, the most obvious choice is to name the fragment file after the package name. Using Audacity again, as an example, create /etc/apt/preferences.d/audacity.pref
with this command:
sudo bash -c 'cat <<EOF > /etc/apt/preferences.d/audacity.pref
Package: audacity
Pin: release *
Pin-Priority: -1
EOF'
Running this command will insert the following 3 lines into the file:
Package: audacity
Pin: release *
Pin-Priority: -1
The Pin-Priority value of -1
prevents the version from being installed, and you can verify there is no installable candidate using the same command earlier:
apt-cache policy audacity
The output will reveal which candidate is available for installation.
audacity:
Installed: (none)
Candidate: (none)
Version table:
2.3.3-1build1 500
500 http://archive.myasnchisdf.eu.org/ubuntu focal/universe amd64 Packages
By using the application’s name as the filename of the apt preferences fragment file, we have a predictable and organised layout for apt preferences. This way, all the configurations for apt preferences are intuitive, human-readable, and uniform. These are desirable qualities for programmatically changing apt preferences at scale using tools like Landscape.