The ‘apt update’ Nightmare When Managing Large Systems
Managing one or two VPS instances? Running sudo apt update only takes a few seconds. But imagine you have a cluster of 50 or 100 Ubuntu servers. When you run update commands simultaneously, international bandwidth will suffer, and you’ll be left frustrated waiting for snail-paced speeds.
The biggest risk isn’t just speed; it’s consistency. One fine day, an official mirror updates to a new version and accidentally breaks your application. Without an internal repository, you’re almost powerless to force all servers to use a specific, tested package version.
I once managed a system with over 20 nodes running Ubuntu Server 22.04. At the time, setting up a Local APT Repository was the top priority to keep everything under control. And Aptly was the most effective ‘assistant’ I trusted.
Why Aptly and Not Other Tools?
You might have heard of reprepro or dpkg-scanpackages, but Aptly is in a different league. Its killer feature is the ability to create Snapshots. You can capture the state of a repository at a specific point in time, test it thoroughly in Staging, and then publish it to the entire Production environment. If something goes wrong? Rolling back to an old snapshot takes only seconds.
Step 1: Install Aptly on Ubuntu Server
Instead of using the outdated version in the Ubuntu repo, I recommend installing directly from Aptly’s official repository to get all the latest features.
# Add Aptly's GPG key
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/aptly-archive-keyring.gpg --keyserver keyserver.ubuntu.com --recv-keys ED75B5A4483DA07C
# Add source list
echo "deb [signed-by=/usr/share/keyrings/aptly-archive-keyring.gpg] http://repo.aptly.info/ squeeze main" | sudo tee /etc/apt/sources.list.d/aptly.list
# Install Aptly
sudo apt update
sudo apt install aptly -y
Step 2: Create a Local Repository for Custom Packages
If you have custom-built .deb files (like internal app source code or custom tools), this is where you’ll store them.
# Create a repository named 'internal-tools'
aptly repo create -comment="Company internal software" -component="main" -distribution="jammy" internal-tools
Once created, simply push your .deb files into it:
# Add package to repo
aptly repo add internal-tools /path/to/your/packages/*.deb
Step 3: Mirror Official Repositories (If Needed)
To save bandwidth, you can mirror official repositories like Ubuntu, Docker, or Nginx to your internal server. However, be mindful of disk space. A full mirror of Ubuntu 22.04 can consume over 150GB—a significant amount.
# Example: Mirror Nginx repo for Ubuntu Jammy
aptly mirror create nginx-mirror https://nginx.org/packages/ubuntu/ jammy main
aptly mirror update nginx-mirror
Step 4: Snapshot and Publish – The Secret to System Stability
Aptly doesn’t allow you to use raw repo data directly. You must create a Snapshot. This is how I control versions to ensure servers don’t update randomly.
# Create a snapshot from the local repo
aptly snapshot create internal-v1.0 from repo internal-tools
# Publish this snapshot so other machines can see it
aptly publish snapshot internal-v1.0
After running this command, the files ready for serving will be located in the ~/.aptly/public directory.
Step 5: Use Nginx to Distribute Packages via HTTP
For other servers to pull packages, we need a ‘delivery man.’ Nginx is the top choice due to its lightweight and stable nature.
sudo apt install nginx -y
Configure the Nginx file at /etc/nginx/sites-available/aptly:
server {
listen 80;
server_name apt.yourdomain.local;
location / {
root /home/ubuntu/.aptly/public;
autoindex on; # Must be enabled for APT to see the file list
}
}
Enable the configuration and reload Nginx:
sudo ln -s /etc/nginx/sites-available/aptly /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
Client-side Configuration: Reaping the Rewards
On the client machine, simply point the address to the Aptly server you just built. Add the following line to the /etc/apt/sources.list.d/internal.list file:
deb http://apt.yourdomain.local/ jammy main
Now, try running sudo apt update. You’ll be surprised by how fast the packages download.
Real-world Operational Experience
After running this system for a while, I’ve gathered two critical points you should keep in mind:
- Periodic Cleanup: The
~/.aptlydirectory will grow extremely fast if you create snapshots continuously without deleting old ones. Runaptly db cleanupregularly to free up space for unused files. - Check Nginx Logs: If a client reports a 404 error, chances are you added a package but forgot to run
aptly publish update. Checking/var/log/nginx/access.logwill help you diagnose the issue very quickly.
In practice, the secret to staying organized is always naming Snapshots with the date, for example, internal-20240426. This approach helps you track the system’s change history visually.
Mastering Aptly doesn’t just solve your bandwidth problems; it’s also a key stepping stone toward building a professional CI/CD pipeline for your Ubuntu infrastructure.

