Learn how to configure the local APT repository in Debian based Linux systems. Useful article for package management on Linux.
APT is package manager that handles Debian packages (.deb). Linux distributions like Ubuntu, Debian uses APT whereas Red Hat, CentOS uses YUM. The package repository is an index of packages that can be used to search, view, install & update packages for Linux In this article, we will be walking through steps to configure the local APT repository.
APT has two types of repositories: complex and simple. We will see a simple repository configuration in this article. For example, we will be keeping two packages in our repository and configure APT to use it. If you know, you can even download packages in .deb format from existing APT repositories! We are keeping our test packages under
/usr/mypackages directory. You can choose your own path.
Rest of the process consist of only 3 steps :
- Store packages in the designated directory
- Scan that directory to create an index
- Add index file path to /etc/apt/sources.list
Step 1 :
Store packages in directory (
/usr/mypackages in our case here). I kept below two packages :
# ll /usr/mypackages total 156 -rw-r--r-- 1 root root 136892 May 17 10:19 python_2.7.11-1_amd64.deb -rw-r--r-- 1 root root 11064 May 17 10:20 python-tdb_1.3.8-2_amd64.deb
Scan packages directory with command
dpkg-scanpackages. This command takes two arguments: first is a directory to scan and the second is override file. For simple repositories, we don’t need an override file so we can use
/dev/null as the second argument.
If you get
The program 'dpkg-scanpackages' is currently not installed. error then you need to install package dpkg-dev on your server.
# dpkg-scanpackages . /dev/null Package: python Source: python-defaults Version: 2.7.11-1 Architecture: amd64 Maintainer: Ubuntu Developers <firstname.lastname@example.org> Installed-Size: 635 Pre-Depends: python-minimal (= 2.7.11-1) Depends: python2.7 (>= 2.7.11-1~), libpython-stdlib (= 2.7.11-1) Suggests: python-doc (= 2.7.11-1), python-tk (>= 2.7.11-1~) Conflicts: python-central (<< 0.5.5) Breaks: update-manager-core (<< 0.200.5-2) Replaces: python-dev (<< 2.6.5-2) Provides: python-ctypes, python-email, python-importlib, python-profiler, python-wsgiref Filename: ./python_2.7.11-1_amd64.deb Size: 136892 MD5sum: af686bd03f39be3f3cd865d38b44f5bf SHA1: eb433da2ec863602e32bbf5569ea4065bbc11e5c SHA256: 5173de04244553455a287145e84535f377e20f0e28b3cec5a24c109e3fa3f088 Section: python Priority: standard Multi-Arch: allowed Homepage: http://www.python.org/ Description: interactive high-level object-oriented language (default version) Python, the high-level, interactive object oriented language, includes an extensive class library with lots of goodies for network programming, system administration, sounds and graphics. . This package is a dependency package, which depends on Debian's default Python version (currently v2.7). Original-Maintainer: Matthias Klose <email@example.com> Package: python-tdb Source: tdb Version: 1.3.8-2 Architecture: amd64 Maintainer: Ubuntu Developers <firstname.lastname@example.org> Installed-Size: 50 Depends: libtdb1 (= 1.3.8-2), python (<< 2.8), python (>= 2.7~), python:any (>= 2.7.5-5~), libc6 (>= 2.2.5), libpython2.7 (>= 2.7) Provides: python2.7-tdb Filename: ./python-tdb_1.3.8-2_amd64.deb Size: 11064 MD5sum: 05035155e6baf5700a19fb8308beeca1 SHA1: bd9ec7d2a902e6997651efeaa0842bfb4a782862 SHA256: c53fd7dae63a846cc9583c174e1def248f9def2c4208923704f964068f0a5ea5 Section: python Priority: optional Homepage: http://tdb.samba.org/ Description: Python bindings for TDB This is a simple database API. It is modelled after the structure of GDBM. TDB features, unlike GDBM, multiple writers support with appropriate locking and transactions. . This package contains the Python bindings. Original-Maintainer: Debian Samba Maintainers <email@example.com> dpkg-scanpackages: warning: Packages in archive but missing from override file: dpkg-scanpackages: warning: python python-tdb dpkg-scanpackages: info: Wrote 2 entries to output Packages file.
You can see in above output,
dpkg-scanpackages checks all packages list their details on terminal. Since command sends output to stdout we will pipe this output with gunzip to create gz index file.
# dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz dpkg-scanpackages: warning: Packages in archive but missing from override file: dpkg-scanpackages: warning: python python-tdb dpkg-scanpackages: info: Wrote 2 entries to output Packages file. # ll -rw-r--r-- 1 root root 1130 May 17 10:27 Packages.gz
Now your index file is ready to be used by APT. You need to let APT know that a new index is created and can be used as a new location to scan packages.
Update the APT configuration file
/etc/apt/sources.list with path of the newly created index file. Add below line :
deb file:/usr/mypackages ./
Thats it! Its done. Run apt update to pickup this new repo.
# apt update Get:1 file:/usr/mypackages ./ InRelease Ign:1 file:/usr/mypackages ./ InRelease Get:2 file:/usr/mypackages ./ Release Err:2 file:/usr/mypackages ./ Release File not found - /usr/mypackages/./Release (2: No such file or directory) Hit:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial InRelease Hit:4 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial-updates InRelease Hit:5 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease Get:6 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] Get:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [265 kB] Reading package lists... Done E: The repository 'file:/usr/mypackages ./ Release' does not have a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details.
You can see in the above output there are security warnings since e haven’t added release files in our directory. We had configured only simple repo hence we just stick with .deb packages and rest files not included.