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
Table of Contents
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:
- Dependency Resolution: APT automatically handles dependencies, ensuring that all required libraries and packages are installed for a given software.
- Repositories: APT uses repositories, which are collections of software packages, to provide a central source for downloading and updating software.
- Commands: Common APT commands include
apt-get
for package installation and removal,apt-cache
for searching and displaying package information, andapt
for an enhanced command-line interface with more user-friendly outputs. - 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:
- Bandwidth Savings: By hosting packages locally, multiple machines can download updates and software without repeatedly accessing external internet resources.
- Speed: Downloading from a local network is typically faster than fetching packages from remote servers.
- Customization: Administrators can include custom packages or specific versions of software not available in the official repositories.
- 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

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
HP Stream 14″ HD BrightView Laptop, Intel Celeron N4120, 16GB RAM, 288GB Storage (128GB eMMC + 160GB Docking Station Set), Intel UHD Graphics, 720p Webcam, Wi-Fi, 1 Year Office 365, Win 11 S, Silver
$309.00 (as of March 7, 2025 18:54 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)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
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) ...
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
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 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
Rules updated
Rules updated (v6)
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
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.
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
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.
Install Libby on Kindle Fire 2025 Easy Step by Step Guide.: And the (APK Method)
$1.99 (as of March 7, 2025 18:51 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)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!
FAQs
1. What is a local APT repository?
A local APT repository is a collection of Debian packages stored on your system or network, allowing you to install and update software without relying on external repositories.
2. Why create a local APT repository?
Creating a local APT repository is useful for offline systems, faster package installations, or distributing custom software within a network.
3. How do I create a local APT repository?
- Place
.deb
packages in a directory (e.g.,/var/www/html/repo
). - Use
dpkg-scanpackages
to generate thePackages.gz
file. - Serve the directory using a web server like Apache.
4. How do I configure clients to use the local APT repository?
Add the repository URL to /etc/apt/sources.list
and update the package list with sudo apt update
.
5. Can I host the repository on a network share?
Yes, you can host the repository on a network share (e.g., NFS or Samba) and configure clients to access it.
Leave a Reply
You must be logged in to post a comment.