Apt Pinning on Ubuntu

Apt pinning is a method that allows you to remain on a stable release of Ubuntu (or other Debian based OS) while grabbing packages from a more recent version.

The solution is to link the apt repository of a more recent version of Ubuntu, yet maintain the default release repository as the current version of Ubuntu. This following example shows linking to Ubuntu Xenial (16.04) apt repository from a Ubuntu Trusty (14.04) installation.

$ echo 'deb http://archive.ubuntu.com/ubuntu xenial main restricted universe
  deb-src http://archive.ubuntu.com/ubuntu xenial main restricted universe' | sudo tee /etc/apt/sources.list.d/ubuntu-xenial.list

$ echo 'APT::Default-Release "trusty"' | sudo tee /etc/apt/apt.conf.d/01ubuntu-trusty

To install a specific package from the more recent version of Ubuntu, simple add '-t <version name>' to the apt-get install command. An example is provided below.

$ sudo apt-get install -y -t xenial mercurial mercurial-keyring tortoisehg