Share on Social Media

Learn how to create local APT repository in Ubuntu 20.04 with this comprehensive guide. Simplify package management and streamline software installations on your Ubuntu system. #centlinux #linux #ubuntu

What is APT?

APT (Advanced Package Tool) is a package management system used by Debian-based Linux distributions, such as Ubuntu, to manage software installations and updates. It simplifies the process of installing, upgrading, configuring, and removing software packages. Key features of APT include:

  1. Dependency Resolution: APT automatically handles dependencies, ensuring that all required libraries and packages are installed for a given software.
  2. Repositories: APT uses repositories, which are collections of software packages, to provide a central source for downloading and updating software.
  3. Commands: Common APT commands include apt-get for package installation and removal, apt-cache for searching and displaying package information, and apt for an enhanced command-line interface with more user-friendly outputs.
  4. Configuration Files: APT configuration files, located in /etc/apt/, allow users to specify repository sources and customize package management settings.

APT streamlines the management of software on Debian-based systems, making it easier for users and administrators to maintain their systems.

What is Local APT repository?

A local APT repository is a storage location on a local network or computer where Debian package files (.deb) and metadata are hosted. This repository allows users to manage and distribute software packages within a closed environment, such as a corporate network or development team. It offers several benefits:

  1. Bandwidth Savings: By hosting packages locally, multiple machines can download updates and software without repeatedly accessing external internet resources.
  2. Speed: Downloading from a local network is typically faster than fetching packages from remote servers.
  3. Customization: Administrators can include custom packages or specific versions of software not available in the official repositories.
  4. Control: Ensures all systems use the same set of approved packages, maintaining consistency and security.

There are situations, where we do not have access to Internet or our Ubuntu machines are not connected to Internet due to some security reasons.

In such cases, you can setup your own local APT repository and use it to install software packages on your Ubuntu machines.

Recommended Online Training: Learn Bash Shell in Linux for Beginners

745772 0021

Environment Specification

We are using a minimal Ubuntu 20.04 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – Ubuntu Server 20.04 LTS
  • Hostname – local-apt-repo.centlinux.com
  • IP Address – 192.168.116.239 /24

Update List of Available APT Packages

Update APT packages list by executing following command at Linux shell.

$ sudo apt-get update

Install DPKG-DEV on Ubuntu 20.04

You are required to install dpkg-dev package, to create the packages meta data for your local APT repository.

$ sudo apt-get install -y dpkg-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9
fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl
libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1
libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0
libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev
libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev
libtsan0 libubsan1 linux-libc-dev make manpages-dev
Suggested packages:
binutils-doc cpp-doc gcc-9-locales debian-keyring g++-multilib
g++-9-multilib gcc-9-doc gcc-multilib autoconf automake libtool flex bison
gdb gcc-doc gcc-9-multilib glibc-doc bzr libstdc++-9-doc make-doc
The following NEW packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9
dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl
libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1
libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0
libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev
libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev
libtsan0 libubsan1 linux-libc-dev make manpages-dev
0 upgraded, 41 newly installed, 0 to remove and 23 not upgraded.
Need to get 40.0 MB of archives.
After this operation, 175 MB of additional disk space will be used.
...Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

Install Apache on Ubuntu 20.04

If you are planning to configure your local APT repository for use by other Ubuntu 20.04 LTS machines on your network. Then you should install Apache web server to host your APT repository.

$ sudo apt-get install -y apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap libjansson4 liblua5.2-0 ssl-cert
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap libjansson4 liblua5.2-0 ssl-cert
0 upgraded, 11 newly installed, 0 to remove and 45 not upgraded.
Need to get 1,865 kB of archives.
After this operation, 8,080 kB of additional disk space will be used.
...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

Configure Ubuntu Firewall

Allow Apache service port in Linux firewall by executing ufw command.

$ sudo ufw allow http
Rules updated
Rules updated (v6)

Create Local APT Repository Directory

Create a directory ‘repo’ within Apache document root, to host your local APT repository.

$ sudo mkdir /var/www/html/repo

Mount the Ubuntu DVD at /mnt/cdrom.

$ sudo mkdir /mnt/cdrom
$ sudo mount /dev/cdrom /mnt/cdrom
mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.

Find and copy all the *.deb packages into our local APT repository.

$ sudo find /mnt/cdrom -iname *.deb -exec cp {} /var/www/html/repo ;

Check the files that was copied by previous command.

$ ls /var/www/html/repo/

Write Bash script to auto-update Package.gz File

Create a script file to scan and update the Packages.gz file.

It is required, because you may add new .deb packages in your local APT repository, time to time. Therefore, you are required to update the Packages.gz file, each time after add a new .deb file in repo directory.

$ sudo nano /bin/update-mydebs

Add following lines of code in this file.

#!/bin/bash
cd /var/www/html/repo
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

Grant execute permissions to update-mydebs script.

$ sudo chmod u+x /bin/update-mydebs

Now, execute this script to create or update Packages.gz file.

$ sudo /bin/update-mydebs
dpkg-scanpackages: warning: Packages in archive but missing from override file:
dpkg-scanpackages: warning: amd64-microcode crda efibootmgr grub-common grub-efi grub-efi-amd64 grub-efi-amd64-bin grub-efi-amd64-signed grub-gfxpayload-lists grub-pc grub-pc-bin grub2-common intel-microcode iucode-tool iw jfsutils kpartx-boot libdbus-glib-1-2 libfreetype6 libnl-3-200 libnl-genl-3-200 libnvpair1linux libuutil1linux libwrap0 libzfs2linux libzpool2linux linux-firmware linux-generic linux-generic-hwe-20.04 linux-headers-5.4.0-65 linux-headers-5.4.0-65-generic linux-headers-5.8.0-41-generic linux-headers-generic linux-headers-generic-hwe-20.04 linux-hwe-5.8-headers-5.8.0-41 linux-image-5.4.0-65-generic linux-image-5.8.0-41-generic linux-image-generic linux-image-generic-hwe-20.04 linux-modules-5.4.0-65-generic linux-modules-5.8.0-41-generic linux-modules-extra-5.4.0-65-generic linux-modules-extra-5.8.0-41-generic mokutil multipath-tools-boot ncurses-term openssh-server openssh-sftp-server os-prober reiserfsprogs shim shim-signed ssh-import-id thermald wireless-regdb zfs-initramfs zfs-zed zfsutils-linux
dpkg-scanpackages: info: Wrote 58 entries to output Packages file.

Your local APT repository has been successfully setup. You can now add it in the sources.list file of your Ubuntu 20.04 machines.

Create Local APT Repository in Ubuntu 20.04

Edit sources.list file in nano text editor.

$ sudo nano /etc/apt/sources.list

And add following lines at the end of this file.

# Local APT Repository
deb [allow-insecure=yes] http://local-apt-repo.centlinux.com/repo ./

Execute apt-get command to update packages list.

$ sudo apt-get update

Ignore the warning about the release file.

Try to install a package from your local APT repository.

$ sudo apt install jfsutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
jfsutils
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 195 kB of archives.
After this operation, 1,616 kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
jfsutils
Install these packages without verification? [y/N] y
Get:1 http://local-apt-repo.centlinux.com/repo ./ jfsutils 1.1.15-4 [195 kB]
Fetched 195 kB in 0s (3,991 kB/s)
Selecting previously unselected package jfsutils.
(Reading database ... 77573 files and directories currently installed.)
Preparing to unpack .../jfsutils_1.1.15-4_amd64.deb ...
Unpacking jfsutils (1.1.15-4) ...
Setting up jfsutils (1.1.15-4) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for initramfs-tools (0.136ubuntu6.3) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-66-generic

Your required package has been installed successfully.

If you are new to Linux and facing difficulty in working at Linux Bash prompt. We recommend that, you should read The Linux Command Line, 2nd Edition: A Complete Introduction by William Shotts.

Final Thoughts

Final Thoughts

Creating a local APT repository in Ubuntu 20.04 can significantly streamline your package management process, ensuring faster installations, reduced bandwidth usage, and greater control over software distribution within your network. By setting up a local repository, you can maintain consistency and efficiency across your systems.

If you need professional assistance with setting up a local APT repository or have other Linux system administration needs, I offer expert services to help you achieve your goals. Visit my Fiverr gig to learn more about how I can assist you in optimizing your Ubuntu environment. Let’s ensure your software distribution is seamless and effective with a local APT repository!

2 thoughts on “Create Local APT Repository in Ubuntu 20.04”
  1. Hi, this tutorial is written for an offline Ubuntu server. It looks like your machine is connected to Internet, that is why it manages to pull the packages from online repositories.

    However, you can comment out (#) all online repositories in sources.list file to achieve the desired result.

Leave a Reply