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 by dpkg-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 install dpkg-dev
package to avail the dpkg-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 the internet. Whereas apt-ftparchive
command is provided by apt-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 to 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 don't set [trusted=yes]
, you'll need to set --allow-unauthenticated
argument while installing packages through apt
.
The line is added to the top of repositories' list to give it the 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 the 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 the highest priority
You 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 which would be i) ftp:// for packages you have in your local repository and/or ii) http:// for packages or missing dependencies required to be downloaded from Internet.
You may have a look at one script called Local Apt Repository Manager I have created.
dpkg -i <packagename>
withapt-get -f install
to pull in required packages. Also, the usual thing to create an apt repos for Debian is reprepro.apt
with--fix-broken
would be required after installing a local package withdpkg -i
? Wouldn't dpkg take care of that? I read it may be required the first time apt is run? @FM&Gilles: About reprepro. Seems useful if I could get it to work (not sure about dir struct, contents of 3 files or params at runtime). Will try again and update or post full question.dpkg
does not resolve dependencies, butapt
does.dpkg
will warn of broken dependencies, but is low level, so will not attempt to fix them. Thedpkg -i *.deb
followed byapt-get -f install
is standard procedure. There is a wishlist bug to haveapt
itself handle the case of local package installation, and there is even a patch, I think, but it has not yet been implemented. See apt-get install could install local package files, too, originally filed in 1999.