Ubuntu – How to add a repository, but only for a specific package/version and its dependencies

aptpackage-managementpinningrepository

I would like to use the Natty Narwhal repository for puppet packages, but I don’t want to upgrade my whole server. Is that possible ?

My current solution is to fetch the .deb packages by hand

Best Answer

Pinning is an advanced package management technique that allows you to remain on a stable release while grabbing packages from a more recent version. Mixing repositories is not supported, and can get you into trouble if the package you want has been compiled against different library versions than you have on your system. If possible, you should try getting the package from the backports repository (or possibly a well supported PPA) first. That said, you seem to already know that puppet from Natty works well on your system.

In order to pin puppet to the natty version, we will have to edit a few files. First you will need to set your default release in /etc/apt/apt.conf.d/01ubuntu (I'm assuming you are using lucid, obviously substitute the actual release):

APT
{
Default-Release "lucid";
};

Next, you need to add natty to your /etc/apt/sources.list or create a the new file /etc/apt/sources.list.d/natty.sources.list with the following sources:

deb http://archive.ubuntu.com/ubuntu natty main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu natty main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu natty-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu natty-updates main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu natty-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu natty-security main restricted universe multiverse

Then, you need to set the "Pin-Priority" for the puppet package from Natty higher than the priority for your default release. Setting the default release in /etc/apt/apt.conf.d/01ubuntu essentially sets the priority for all packages originating in that release to 990. So in /etc/apt/preferences we need to over-ride this for puppet, using something higher like:

Package: puppet
Pin: release n=natty
Pin-Priority: 995

Now you simply need to run and apt-get update && apt-get upgrade

Related Question