Make apt-get use an alternate sources.list

Since my [former] company's product is based on ubuntu, we use apt to distribute upgrades. We don't normally want customers to pull upgrades from the upstream distribution, so we've pruned back the main /etc/apt/sources.list to include just our server. We rename the original default sources.list so that it doesn't get picked up.

But sometimes I want to be able to pull from upstream, so I want to reactivate the original sources.list. Up to now, I've been having to do an awkward dance that involves renaming our file, copying the old default to the active, and then doing the reverse when I'm done.

(As an aside, yum-based systems like Centos or Fedora make this easy. You can say enable=0 in the list file, and then use --enablerepo=myrepo on the command line. There doesn't seem to be a way to do this with apt, but the command below is almost as good.)

To avoid this renaming dance, here's a better solution.

First, create a directory to put the original sources.list: /etc/apt/sources.list.ubuntu.

Then copy the original default sources.list into that directory. I called it /etc/apt/sources.list.ubuntu/jaunty.list.

When you want to pull from upstream, run:

apt-get -o Dir::Etc::SourceParts=/etc/apt/sources.list.ubuntu install some-new-package

Then you'll want to run apt-get update to reset your repository list back to the trimmed-down set.

Posted on 2011-01-06 by brian in news .
Comments on this post are closed. If you have something to share, please send me email.