How to have a private APT configuration without being root

Say you're working on a Debian box for which you don't have root access, you need to get some source packages, but there is no deb-src lines (or not the ones you need) in /etc/apt/sources.list. So usually you will have to manually wget the files, after looking the exact location, and all that jazz.

Today I found that APT can be configured to use a different sources.list file, and different directories for the package lists. Which is enough to make it work for downloading source packages.

What you need to do is:

$ mkdir apt
$ cp /etc/apt/sources.list apt/
$ vi apt/sources.list
# customise as needed
$ mkdir -p apt/lists/partial
$ cat > apt/apt.conf
Dir::Etc::SourceList "
home_dir/apt/sources.list"; # You need to use the full path
Dir::State::Lists "
home_dir/apt/lists";
^D
$ export APT_CONFIG=~/apt/apt.conf
$ apt-get update
...
$ apt-get source foo

After downloading the lists, it will complain about it not being able to lock the dpkg directory, but no need to worry. It will work perfectly.