How to use backports repository

Backport repository provides packages for stable system that are recompiled from testing or unstable distribution. It is important to know that these packages are provided as is without any security support guarantee.

Configure backports repository

Add stretch-backports repository.

$ cat <<EOF | sudo tee /etc/apt/sources.list.d/stretch-backports.list
deb http://http.debian.net/debian stretch-backports main
EOF
deb http://http.debian.net/debian stretch-backports main

Update package index.

$ sudo apt-get update

Install package directly from backports repository

You can install package directly from backports repository by specifing it on the command-line.

Display available haproxy versions.

$ apt-cache policy haproxy
haproxy:
  Installed: (none)
  Candidate: 1.7.5-2
  Version table:
     1.7.9-1~bpo9+1 100
        100 http://http.debian.net/debian stretch-backports/main amd64 Packages
     1.7.5-2 500
        500 http://ftp.task.gda.pl/debian stretch/main amd64 Packages

backports repository has priority of 100 (it default value since squeeze-backports), so it will be ignored during standard operations as distribution packages have priority of 100.

$ sudo apt-get install haproxy --dry-run
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  liblua5.3-0
Suggested packages:
  vim-haproxy haproxy-doc
The following NEW packages will be installed:
  haproxy liblua5.3-0
0 upgraded, 2 newly installed, 0 to remove and 6 not upgraded.
Inst liblua5.3-0 (5.3.3-1 Debian:9.1/stable [amd64])
Inst haproxy (1.7.5-2 Debian:9.1/stable [amd64])
Conf liblua5.3-0 (5.3.3-1 Debian:9.1/stable [amd64])
Conf haproxy (1.7.5-2 Debian:9.1/stable [amd64])

Specify desired repository on the command-line to install package directly from backports repository.

$ sudo apt-get install -t stretch-backports haproxy --dry-run
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  liblua5.3-0
Suggested packages:
  vim-haproxy haproxy-doc
The following NEW packages will be installed:
  haproxy liblua5.3-0
0 upgraded, 2 newly installed, 0 to remove and 31 not upgraded.
Inst liblua5.3-0 (5.3.3-1 Debian:9.1/stable [amd64])
Inst haproxy (1.7.9-1~bpo9+1 Debian Backports:stretch-backports [amd64])
Conf liblua5.3-0 (5.3.3-1 Debian:9.1/stable [amd64])
Conf haproxy (1.7.9-1~bpo9+1 Debian Backports:stretch-backports [amd64])
$ sudo apt-get install -t stretch-backports haproxy

This package will be upgraded from the same repository as apt will install the most recent version if it encounters two or more package versions that have the same priority.

Install package indirectly from backports repository

like the Debian backports archive since squeeze-backports.

$ cat << EOF | sudo tee /etc/apt/preferences.d/90_stretch-backports_packages
Package: tmux
Pin: release n=stretch-backports
Pin-Priority: 1000
EOF
Package: tmux
Pin: release n=stretch-backports
Pin-Priority: 1000
sz@debian:/etc/apt/apt.conf.d$ apt-cache policy tmuxtmux:
  Installed: (none)
  Candidate: 2.5-2~bpo9+1
  Version table:
     2.5-2~bpo9+1 1000
        100 http://http.debian.net/debian stretch-backports/main amd64 Packages
     2.3-4 500
        500 http://ftp.task.gda.pl/debian stretch/main amd64 Packages
milosz@debian:/etc/apt/apt.conf.d$ apt-get install tmux --dry-run
NOTE: This is only a simulation!
      apt-get needs root privileges for real execution.
      Keep also in mind that locking is deactivated,
      so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libevent-2.0-5 libutempter0
The following NEW packages will be installed:
  libevent-2.0-5 libutempter0 tmux
0 upgraded, 3 newly installed, 0 to remove and 7 not upgraded.
Inst libevent-2.0-5 (2.0.21-stable-3 Debian:9.1/stable [amd64])
Inst libutempter0 (1.1.6-3 Debian:9.1/stable [amd64])
Inst tmux (2.5-2~bpo9+1 Debian Backports:stretch-backports [amd64])
Conf libevent-2.0-5 (2.0.21-stable-3 Debian:9.1/stable [amd64])
Conf libutempter0 (1.1.6-3 Debian:9.1/stable [amd64])
Conf tmux (2.5-2~bpo9+1 Debian Backports:stretch-backports [amd64])
$ cat << EOF | sudo tee /etc/apt/preferences.d/89_stretch-backports_default
Package: *
Pin: release n=stretch-backports
Pin-Priority: -1
EOF

Additional notes

Priorities are extensively described in apt_preferences manual page.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.

Gdansk, Poland https://sleeplessbeastie.eu