Debian – How to quickly create a local apt repository for random packages using a Debian based linux distribution

aptdebianpackage-management

Some situations call for manually installing a local package using dpkg -i <packagename>. Sometimes it may be further useful to leverage the functionality of apt with that package so the question is:

How do you quickly create a local repository for random packages using a Debian based linux distribution – like Xubuntu 13.04/Ubuntu?

Best Answer

This should be distinguished from the situation where you're trying to replicate a full package tree from an official repository and fine tuning sources priority. Random packages mean virtual packages, packages which are compiled locally or copied in a piecemeal fashion for testing purposes. Here's a simple setup based on now obsolete documentation.

First, make a directory to host the packages:

mkdir <packagedir>

Then move your .deb package files there. Execute this command from the directory above the one we just created (make sure permissions allow this!):

dpkg-scanpackages packagedir | gzip > packagedir/Packages.gz

Now create a file with extension .list in /etc/apt/sources.list.d/ with the contents:

deb [trusted=yes] file:///path_to_dir_above_packagedir packagedir/

and update the apt database:

apt-get update

At this point the packages in our local repository can be installed like any other package using apt-get install <packagename>. When new packages are added to the local repository, the prescribed dpkg-scanpackages command must be issued again to update the Packages.gz file and apt must be updated before the new packages are made available. Hopefully this can be useful for testing purposes.

Related Question