How to quickly create a local apt repository for random packages using a Debian based linux distribution?
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.
If you want to create a repo with the full structure that you need for tools like debootstrap, the simplest way I've found is:
Create a repository directory.
# mkdir -p /opt/debian/conf
Create an
/opt/debian/conf/distributions
file with contents like this (adjust as appropriate for the distribution you're using):Label: Local APT repository Codename: jessie Architectures: amd64 Components: main Description: Local APT repository for debootstrap
Import your package with
reprepro
:# reprepro -b /opt/debian includedeb jessie /path/to/package.db
Import a bunch of packages with a shell for-loop, e.g.. everything from your APT cache:
# cd /var/cache/apt/archives # for DEB in *.deb do reprepro -b /opt/debian includedeb jessie "$DEB" done
This will create an unsigned archive.
It can be used with debootstrap with the --no-check-gpg
option.
Though a similar answer already exist and several similar answers are there on AU also, I am posting this answer to recommend the use of apt-ftparchive
instead of dpkg-scanpackages
Why apt-ftparchive
instead of dpkg-scanpackages
?
dpkg-scanpackages
command is provided bydpkg-dev
package which doesn't come with installation image of distribution, as per my observation, it may not be installed on your machine. You will first need to installdpkg-dev
package to availdpkg-scanpackages
command. And the aim of setting up local repository is usually to manage software packages offline, on a machine which is not connected to internet. Whereasapt-ftparchive
command is provided byapt-utils
which comes with the usual installation image of the distribution. So, you don't need to install any extra packages.Since we are about to do package-management using apt instead of dpkg, why not use apt for scanning packages also? :)
How to setup APT local repository?
Step 1: Create a directory in which you'll put your debs.
$ mkdir ~/apt-local-repository
Step 2: Add your local directory to the top of repositories' list at /etc/apt/sources.list
$ head -n 1 /etc/apt/sources.list
deb [trusted=yes] file:/home/pandya/apt-local-repository/ ./
Note that if you'll not set
[trusted=yes]
, you'll need to set--allow-unauthenticated
argument while installing packages throughapt
.The line is added to the top of repositories' list to give it highest priority. If you add it to
/etc/apt/sources.list.d/
instead, apt will try to install it from online repository (as defined at/etc/apt/sources.list
) giving your local repository less priority.
Step 3: Put your debs to ~/apt-local-repository
Step 4: Indexing package list using aptftparchive
$ cd ~/apt-local-repository/; apt-ftparchive packages . > Packages
Step 5: Update the apt index/database using sudo apt update
Done. Now you can install your deb package using sudo apt install <packagename>
. Just repeat steps 3 to 5 every-time you change your local database.
Useful tips:
You can run
apt-cache policy </packagename>
to investigate whether APT is recognizing your local deb package and giving it highest priorityYou can run
sudo apt-get --print-uris install <packagename>
to check whether all dependencies are satisfied or you need to download any extra packages. Also it will list urls while would be i) ftp:// for your local repository of the packages you have and/or ii) http:// for dependency packages you need to download.