05 January 2009

Debian : How to build local APT repositories

1) Create folders for the package files you plan to keep in your repository. Here is an example: in your home folder, create a new folder called repository in which you will keep all your downloaded packages. If you plan to burn the package files onto a CD, I suggest you create separate folders for each disk. The naming is up to you – disk_1, disk_2, etc (I’ll assume this naming convention throughout the rest of the tutorial). This is just to ensure that you use the next folder once your cache reaches the size of a CD (usually 700MB). If you are using a local hard drive or a DVD, you obviously have higher limits to keep in mind. If you do not plan to create a CD/DVD, you may simply dump all the files in the repository folder.

2) The next step is to copy all your deb files (those files that end with .deb) to the repository folder(s). Open Nautilus, navigate to /var/cache/apt/archives and copy all the deb files to the appropriate folder(s). For instance, /home//repository/disk_1 - keep an eye on the size of the folders. To do it in the terminal:

cp /var/cache/apt/archives/*.deb ~/repository/disk_1

If you have many files, it may take quite a while so be patient.

3) Change into your repository folder:

cd ~/repository/disk_1

4) Now do the following command to create the Packages.gz file that is needed to for Synaptic to “see” your repository:

sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

I suggest you copy and paste this to avoid any typos.

  • Please note that every time you add any more .deb files to this folder, you have to create a new Packages.gz file using the above command before the new file(s) will show up in Synaptic (or Aptitude).
  • Be sure to install the build-essential package (sudo aptitude install build-essential) before running the above command.

There are several ways of using your newly created repository.

I) Keeping the files on a local hard disk…

Edit your /etc/apt/sources.list file like so:

gksudo gedit /etc/apt/sources.list

And insert this on a new line (preferably the first):

deb file:/home/username/repository/disk_1/ /

Remember to replace username with your real username.

Reload your package index like this:

sudo aptitude update

II) Using a CD/DVD as a repository:

a) Burn the repository folder onto a CD/DVD

b) With the disc loaded in your drive, fire up Synaptic and click through the menus like this:

Edit –> Add CD Rom.

c) You will be asked to type in a description for the disc; type in anything, for instance: Offline Repository Disk 1.

d) Click Ok.

Summary
Go to /var/cache/apt/archives and copy your debian packages to a folder of your choice, for example, /home//repository/

  • Change into the repository directory

cd /home/username/repository

  • And generate a Packages.gz file like this:

sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

Make sure build-essential is installed (sudo aptitude install build-essential) before you run the above command.

  • Add the following line to your sources.list file (/etc/apt/sources.list)

deb file:/home/username/repository/ /

Remember to replace username with your real username

  • Reload your package index like this:

sudo apt-get update

That’s it… sit back, relax and enjoy the ride.

I found the following tips for using Synaptic very useful:

  • You might want to check out the online sources.list generator. It will let you select various repositories for your sources.list. Once you get the output, simply replace the contents of your /etc/apt/sources.list file with it.
  • Now have a loom at the Synaptic settings (Settings –> Repositories –> Settings).
  • I suggest you decide if you always want to get the highest/latest version or if you want to stick to the feisty version.
  • Also, ensure that you have checked the option that allows downloaded packages to be kept in the cache, otherwise you will just have to download them again if you accidentally do an apt-get autoclean or something similar. Have fun. :)

No comments: