WIP: refactoring of AptConf, AptPreferences and other apt configuration pages


Apt is configured by several resources, including:


apt_preferences

See man 5 apt_preferences

Apt pinning

When multiple Apt repositories are enabled, a package can exist in several of them. To know which one should be installed, Apt assigns priorities to packages. The default is 500.

Pinning allows changing priorities for only some packages/repositories, so that you can:

With a few exceptions it is not recommended to mix repositories/releases unless their are specially prepared . See DontBreakDebian.

To view priority of a specific package, use apt-cache policy:

$ apt-cache policy claws-mail
claws-mail:
  Installed : (none)
  Candidate : 3.14.1-3+b1
 Version table :
     3.17.1-1~bpo9+1 100
        100 https://deb.debian.org/debian stretch-backports/main amd64 Packages
     3.14.1-3+b1 500
        500 https://deb.debian.org/debian stretch/main amd64 Package

Force installation of a newer package

In that case the package that would be installed (Candidate) would be the older, 3.14 version from stretch/main. stretch-backports/main has a newer version 3.17, but a lower priority (100 vs 500 for stretch)

If we really, always want the newer package from stretch-backports, we can configure Apt to do so. Considering your Apt sources are:

# Debian stable
deb http://deb.debian.org/debian stable main #default priority 500
deb http://deb.debian.org/debian stable-backports main #default priority 100

Tell Apt to prefer the package (set a higher priority) from stretch-backports. Edit the file /etc/apt/preferences.d/99debian-backports (create it):

Package: claws-mail
Pin: release a=stretch-backports
Pin-Priority: 900

Now installing the claws-mail package will install the newer version.

Prevent/selective installation from third-party a repository

To prevent installation of newer packages from a third-party repository (don't enable DebianUnstable repositories on Stable, see DontBreakDebian), even if it has equal priority, edit the file /etc/apt/preferences.d/99my-custom-repository:

# Never prefer packages from the my-custom-repo repository
Package: *
Pin: origin o=my-custom-repo
Pin-Priority: 1

# Allow upgrading only my-specific-software from my-custom-repo
Package: my-specific-software
Pin: origin o=my-custom-repo
Pin-Priority: 500

File naming in /etc/apt/preferences.d/ is free but the last in alphabetical order takes precedence.

apt.conf

See man 5 apt.conf

Apt accepts configuration files (without extension) in /etc/apt/apt.conf.d/. These are processed by Apt in numeric/alphabetical order. /etc/apt/apt.conf is also valid but deprecated.

These files can contain various directives:

If you really have to use FTP, this sets the FTP proxy:

 Acquire::ftp
 {
   Proxy "ftp://proxy:2121/";
   ProxyLogin
   {
      "USER $(SITE_USER)@$(SITE)";
      "PASS $(SITE_PASS)";
   }
 }

Command line options

PackageManagementTools such as apt, aptitude, apt-get... allow you to set specific configuration options for a single run. See their respective ?ManPages.


CategoryPackageManagement | CategorySoftware | CategorySystemAdministration