Introduction
Having packages available locally is helpful in a number of situations. Your organization might be using certain packages which are not available on public repositories. You might also be building your own debian packages and would prefer to have them available locally on the system.
In this article, we will show you how to set up a simple local package repository on an Ubuntu 16.04 system.
Step 1: Install dpkg-dev package
To install the dpkg-dev package we will use the following command:
root@linnuxnix:~# apt install dpkg-dev Reading package lists... Done Building dependency tree Reading state information... Done dpkg-dev is already the newest version (1.18.4ubuntu1.3). dpkg-dev set to manually installed. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
The package appears to be already installed. Let’s view some information about the package using dpkg -s command.
root@linnuxnix:~# dpkg -s dpkg-dev Package: dpkg-dev Status: install ok installed Priority: optional Section: utils Installed-Size: 1715 Origin: debian Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Bugs: debbugs://bugs.debian.org Architecture: all Multi-Arch: foreign Source: dpkg Version: 1.18.4ubuntu1.3 Replaces: manpages-it (<< 2.80-4) Depends: libdpkg-perl (= 1.18.4ubuntu1.3), bzip2, xz-utils, patch (>= 2.7), make, binutils, base-files (>= 5.0.0) Recommends: gcc | c-compiler, build-essential, fakeroot, gnupg | gnupg2, gpgv | gpgv2, libalgorithm-merge-perl Suggests: debian-keyring Breaks: devscripts (<< 2.14.10), dpkg-cross (<< 2.0.0) Conffiles: /etc/dpkg/shlibs.default 1a2b9d0a869e2aa885ae3621c557fb95 /etc/dpkg/shlibs.override 84b1e69080569cc5c613a50887af5200 Description: Debian package development tools This package provides the development tools (including dpkg-source) required to unpack, build and upload Debian source packages. . Most Debian source packages will require additional tools to build; for example, most packages need make and the C compiler gcc. Homepage: https://wiki.debian.org/Teams/Dpkg Original-Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
Step 2: Create directory to store packages
In this step, we will create a directory or folder on our local machine on which we will store packages.
root@linnuxnix:~# mkdir /localrepo root@linnuxnix:~# ls -ld /localrepo drwxr-xr-x 2 root root 4096 Dec 20 08:58 /localrepo root@linnuxnix:~#
Step 3: Populate the repository directory with some packages
I’ve just copied a few .deb packages to the /localrepo directory we created in the previous step.
To demonstrate I’ve copied a couple of python packages in the /localrepo directory.
root@linnuxnix:~# ls -ltr /localrepo total 4468 -rw-r--r-- 1 root root 223790 Dec 20 09:01 python2.7_2.7.12-1ubuntu0~16.04.2_amd64.deb -rw-r--r-- 1 root root 1293808 Dec 20 09:01 python2.7-minimal_2.7.12-1ubuntu0~16.04.2_amd64.deb -rw-r--r-- 1 root root 165188 Dec 20 09:01 python3.5_3.5.2-2ubuntu0~16.04.4_amd64.deb -rw-r--r-- 1 root root 1597106 Dec 20 09:01 python3.5-minimal_3.5.2-2ubuntu0~16.04.4_amd64.deb -rw-r--r-- 1 root root 10026 Dec 20 09:01 python3-problem-report_2.20.1-0ubuntu2.14_all.deb -rw-r--r-- 1 root root 79452 Dec 20 09:01 python3-apport_2.20.1-0ubuntu2.14_all.deb -rw-r--r-- 1 root root 83106 Dec 20 09:02 python-html5lib_0.999-4_all.deb -rw-r--r-- 1 root root 96322 Dec 20 09:02 python-chardet_2.3.0-2_all.deb -rw-r--r-- 1 root root 64160 Dec 20 09:02 python-bs4_4.4.1-1_all.deb -rw-r--r-- 1 root root 10900 Dec 20 09:02 python-six_1.10.0-3_all.deb -rw-r--r-- 1 root root 108428 Dec 20 09:02 python-pkg-resources_20.7.0-1_all.deb -rw-r--r-- 1 root root 819312 Dec 20 09:02 python-lxml_3.5.0-1build1_amd64.deb
Step 4: Execute the dpkg-scanpackages command
The dpkg-scanpackages command sorts through a tree of Debian binary packages and creates a Packages file, used by apt to tell the user what packages are available for installation.
These Packages files are the same as those found on Debian archive sites and CD-ROMs.
We will execute this command in the /localrepo repository directory.
root@linnuxnix:/localrepo# dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz dpkg-scanpackages: warning: Packages in archive but missing from override file: dpkg-scanpackages: warning: python-bs4 python-chardet python-html5lib python-lxml python-pkg-resources python-six python2.7 python2.7-minimal python3-apport python3-problem-report python3.5 python3.5-minimal dpkg-scanpackages: info: Wrote 12 entries to output Packages file. root@linnuxnix:/localrepo# ls -l Packages.gz -rw-r--r-- 1 root root 4517 Dec 20 09:08 Packages.gz
If we query the contents of the compressed archive file, we observe that the archive contains information about the packages available in the directory.
root@linnuxnix:/localrepo# zcat Packages.gz Package: python-bs4 Source: beautifulsoup4 Version: 4.4.1-1 Architecture: all Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Installed-Size: 341 Depends: python:any (<< 2.8), python:any (>= 2.7.5-5~) Recommends: python-chardet, python-lxml | python-html5lib Filename: ./python-bs4_4.4.1-1_all.deb Size: 64160 MD5sum: a02c2da0986199d67e05893397d62ee6 SHA1: b7b7eed681e73b4e5e2cc051386dee38cf41da9e SHA256: 9e55c74c9eac4c143e8367c2e7a59b67cf4c1ac098fa3bf05962d21e07e36d52 Section: python Priority: optional Homepage: http://www.crummy.com/software/BeautifulSoup Description: error-tolerant HTML parser for Python Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers hours or days of work. This package contains BeautifulSoup 4, for Python 2.x. Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org> Package: python-chardet Source: chardet -----------------------------------------------output truncated for brevity
Step 5: Create an entry for the local repository in /etc/apt/sources.list/ file
In this step, we will add an entry for our local repository in the /etc/apt/sources.list file to ensure that apt is aware of this repository and any updates made to this repository are reflected in the apt cache when we run apt update.
root@linnuxnix:~# grep localrepo /etc/apt/sources.list deb [trusted=yes] file:///localrepo ./ root@linnuxnix:~#
Step 6: Update ubuntu system cache
We will now execute the apt update command to refresh our system repository cache to make our machine aware of the newly added repository.
root@linnuxnix:~# apt update Get:1 file:/localrepo ./ InRelease Ign:1 file:/localrepo ./ InRelease Get:2 file:/localrepo ./ Release Ign:2 file:/localrepo ./ Release Get:3 file:/localrepo ./ Packages Ign:3 file:/localrepo ./ Packages Get:4 file:/localrepo ./ Translation-en_US Ign:4 file:/localrepo ./ Translation-en_US Get:5 file:/localrepo ./ Translation-en Ign:5 file:/localrepo ./ Translation-en Get:3 file:/localrepo ./ Packages Ign:3 file:/localrepo ./ Packages Get:4 file:/localrepo ./ Translation-en_US Ign:4 file:/localrepo ./ Translation-en_US Get:5 file:/localrepo ./ Translation-en Ign:5 file:/localrepo ./ Translation-en Get:3 file:/localrepo ./ Packages Ign:3 file:/localrepo ./ Packages Get:4 file:/localrepo ./ Translation-en_US Ign:4 file:/localrepo ./ Translation-en_US Get:5 file:/localrepo ./ Translation-en Ign:5 file:/localrepo ./ Translation-en Get:3 file:/localrepo ./ Packages [4,517 B] Get:4 file:/localrepo ./ Translation-en_US Ign:4 file:/localrepo ./ Translation-en_US Get:5 file:/localrepo ./ Translation-en Ign:5 file:/localrepo ./ Translation-en Get:4 file:/localrepo ./ Translation-en_US Ign:4 file:/localrepo ./ Translation-en_US Get:5 file:/localrepo ./ Translation-en Ign:5 file:/localrepo ./ Translation-en Get:4 file:/localrepo ./ Translation-en_US Ign:4 file:/localrepo ./ Translation-en_US Get:5 file:/localrepo ./ Translation-en Ign:5 file:/localrepo ./ Translation-en Hit:6 http://ap-southeast-1.ec2.archive.ubuntu.com/ubuntu xenial InRelease Get:7 http://ap-southeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB] Get:8 http://ap-southeast-1.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB] Get:9 http://ap-southeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [681 kB] Get:10 http://ap-southeast-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [565 kB] Hit:11 http://security.ubuntu.com/ubuntu xenial-security InRelease Fetched 1,451 kB in 0s (1,937 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date. root@linnuxnix:~#
Step 7: Verify that the system is aware of the new repository
We’ll run the apt-cache policy command to list the repositories available to the system to download packages from.
root@linnuxnix:~# apt-cache policy | grep localrepo 500 file:/localrepo ./ Packages root@linnuxnix:~#
Since our localrepo repository is being listed we can confirm that the local repository is now live.
Conclusion
This completes our setup of a local repository to host .deb packages on our Ubuntu system. Please note that you would need to execute the dpkg-scanpackages command followed by apt update every time you add new packages to the local repository.
Sahil Suri
Latest posts by Sahil Suri (see all)
- Google Cloud basics: Activate Cloud Shell - May 19, 2021
- Create persistent swap partition on Azure Linux VM - May 18, 2021
- DNF, YUM and RPM package manager comparison - May 17, 2021
- Introduction to the aptitude package manager for Ubuntu - March 26, 2021
- zypper package management tool examples for managing packages on SUSE Linux - March 26, 2021