How to force apt/apt-get to update to latest version on package server without specifying the version?

How do I force apt/apt-get to update to the latest version of a package that is available on the package server even if this means a downgrade but without specifying the version I want to install.

For example I have foo_0.2 locally installed and the server only has foo_0.1. In that case I want to get foo_0.1 installed.

I know I can manually find out the version available on the package server via apt policy foo and then run apt install foo=0.1.
But is there a command that just installs the latest version that is on the package server without me explicitly specifying the version?

Note: A similar question was asked in How to downgrade a package via apt-get?, but this question here is about downgrading without manually specifying a version.

Asked By: apbr

||

You can try using apt_preferences to accomplish this.

For example, if the "package server" containing the foo package is archive.ubuntu.com then you can configure a preference for this server

cat <<EOF > /etc/apt/preferences.d/50my
Package: *
Pin: origin archive.ubuntu.com
Pin-Priority: 1001
EOF

The Pin-Priority value must be 1000 or higher. From the apt_preferences man page

   P >= 1000
       causes a version to be installed even if this constitutes a downgrade of the package

If you were to run apt-get install foo then the foo package should be downgraded without having to specify the specific version.

I have not tested this setup to verify it works.

Answered By: Andrew Lowther
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.