How to Create Local APT Repository in Ubuntu

Share on Social Media

Learn how to create local APT repository in Ubuntu 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.

Create Local APT Repository in Ubuntu 20.04
Create Local APT Repository in Ubuntu 20.04

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 Training: Linux Administration: The Complete Linux Bootcamp in 2025 from Andrei Dumitrescu, Crystal Mind Academy

3371848 9ea9 18

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

To ensure your system has the most up-to-date information about available software packages, it’s essential to update the APT (Advanced Package Tool) package list. This process refreshes the local database of package metadata, which includes details about the latest versions of software, security patches, and dependencies. By keeping this list current, you can ensure that your system is aware of the newest updates and improvements available for installation.

To update the APT package list, open your Linux shell (terminal) and execute the following command:

sudo apt-get update

Installing DPKG-DEV Packages

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

Installing Apache Web Server

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

Configure UFW Firewall

To ensure that your Apache web server can communicate properly and serve web pages to users, you need to allow its service port through the Linux firewall. On systems using the Uncomplicated Firewall (UFW), which is a user-friendly interface for managing iptables, you can easily enable the necessary ports with a simple command.

By default, Apache listens on port 80 for HTTP traffic and port 443 for HTTPS (encrypted) traffic. To allow these ports, you can execute the following UFW commands in your terminal:

sudo ufw allow http

Create Directory for Local APT Repository

To set up a local APT repository that can be accessed over your network or locally, you’ll need to create a dedicated directory to store the repository files. This directory will serve as the central location for hosting your custom software packages, making them available for installation on other systems within your environment. A common and convenient location for this purpose is within the Apache document root, which is the default directory where Apache serves web content.

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

Output:

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

Output:

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.

Creating Local APT Repository

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

Your required package has been installed successfully.

Frequently Asked Questions (FAQs)

1. What is a local APT repository?

A local APT repository is a storage location (usually on your network or machine) that hosts .deb packages, allowing you to install and update software without relying on external servers like Ubuntu’s official mirrors.

2. Why use a local APT repository?

Benefits include:
✔ Faster package installations (no internet download delays)
✔ Control over available packages (useful for air-gapped systems)
✔ Reduced bandwidth usage in multi-machine environments

3. How do I create a local APT repository?

Basic steps:

  1. Install apt-utils and dpkg-dev.
  2. Place .deb files in a directory (e.g., /var/local/repo).
  3. Run dpkg-scanpackages to generate a Packages.gz index.
  4. Share the repo via HTTP/NFS or use it locally.

4. How do I configure APT to use my local repository?

Add a .list file in /etc/apt/sources.list.d/ with:

deb [trusted=yes] file:/path/to/repo ./  

Then run sudo apt update.

5. Can I mirror official repositories locally?

Yes! Tools like apt-mirror or debmirror download entire Ubuntu/Debian repositories to your server for offline use.

Final Thoughts

Creating a local APT repository in Ubuntu 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.

Searching for a skilled Linux admin? From server management to security, I ensure seamless operations for your Linux systems. Find out more on my Fiverr profile!

Let’s ensure your software distribution is seamless and effective with a local APT repository!

Looking for something?

2 responses to “How to Create Local APT Repository in Ubuntu”

  1. Anonymous Avatar
    Anonymous

    Hi,

    this tut doesn't work at the end, when I want to install something from /var/www/html/repo apt pul packages from official repo not from local.

  2. Ahmer M Avatar

    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