23

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?

8
  • Just FYI. The usual thing is to follow dpkg -i <packagename> with apt-get -f install to pull in required packages. Also, the usual thing to create an apt repos for Debian is reprepro. Aug 17, 2013 at 17:38
  • I've found reprepro helpful Aug 17, 2013 at 21:11
  • Thank you for your comments. @Faheem Mitha: can you please briefly expand on why running apt with --fix-broken would be required after installing a local package with dpkg -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.
    – user44370
    Aug 18, 2013 at 3:49
  • 1
    @illuminÉ : dpkg does not resolve dependencies, but apt does. dpkg will warn of broken dependencies, but is low level, so will not attempt to fix them. The dpkg -i *.deb followed by apt-get -f install is standard procedure. There is a wishlist bug to have apt 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. Aug 18, 2013 at 8:39
  • @illuminÉ Expressing interest in this feature will not hurt. I think the more people who (politely) express interest, the more likely it is that it will be implemented. Note also that gdebi is an alternative, as noted in the bug report. That is part of the reason it has not been implemented, I think. Though having such core functionality part of apt would be better than having this functionality as part of another package. Aug 18, 2013 at 8:42

3 Answers 3

37

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.

1
  • 6
    With the new apt 1.1, one needs [trusted=yes] between deb and the file:/// URI (see the sources.list(5) man page), otherwise apt-get update fails because of the lack of signature.
    – vinc17
    Nov 27, 2015 at 2:31
5

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.

1
  • 1
    thanks for useful tips
    – andrew
    Apr 2, 2021 at 12:03
3

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:

  1. Create a repository directory.

    # mkdir -p /opt/debian/conf
    
  2. 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
    
  3. Import your package with reprepro:

    # reprepro -b /opt/debian includedeb jessie /path/to/package.db
    
  4. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy