How to Set Up a Local Repository on Debian

When you’re managing more than one Debian machine, downloading the same packages over and over again can feel slow and wasteful. A local repository helps with that. It’s a place on your own network where you keep Debian packages, so other computers can install or update software without going to the internet.

In simple words, a repository (or “repo”) is like a warehouse for software. Debian gets its apps and updates from online repos, but you can also make your own. A local repository is one that lives on your own computer or server. It saves bandwidth, speeds up installations, and works even if your internet is down.

I’ll walk you through how to build one. You don’t need to be a Linux expert. I’ve done this myself at home and in small offices, and I’ll explain each step the same way I wish someone had explained it to me.


Why Use a Local Repository?

From my experience, setting up a local repo makes a lot of sense in places where:

  • You have many Debian machines.
  • Your internet is slow or limited.
  • You want to test packages before letting others use them.

Let’s look at some real benefits:

  • Faster installs: Everything loads from your LAN (local network).
  • Less bandwidth: You only download updates once.
  • Custom control: You can include your own .deb packages.

If you’ve ever waited for an update to download ten times on ten computers, this setup can save you a lot of time.


What You’ll Need

Here’s what you should have before you begin:

  • A Debian-based system (Debian, Ubuntu, or similar).
  • At least 1GB of free disk space.
  • An internet connection (at least for the first time).
  • Basic terminal knowledge (copy/paste commands is okay).

You’ll also need:

  • A folder to hold your repo.
  • A way to share it (like a basic web server).

I’ll guide you through using Apache to serve the repo. It’s stable and easy to set up.


Step 1: Create a Directory for Your Repository

First, pick a place to store your packages.

Open your terminal and run:

sudo mkdir -p /opt/debian-repo/bullseye

Here’s what that does:

  • mkdir makes the folder.
  • -p means “make parent folders if they don’t exist.”
  • bullseye is the codename for Debian 11. You can use another codename if needed.

You can store .deb files in that folder later.


Step 2: Install Required Tools

We’ll need a tool called dpkg-scanpackages. It scans your .deb files and builds an index file.

Run this:

sudo apt update
sudo apt install dpkg-dev

That gives you the tools needed to create a working package list.

If you want to test that it’s working:

which dpkg-scanpackages

You should see something like /usr/bin/dpkg-scanpackages.


Step 3: Add Some .deb Files

You can download .deb files manually or copy them from another machine using scp or a USB stick.

Put them inside /opt/debian-repo/bullseye.

For example:

cp myfile.deb /opt/debian-repo/bullseye/

This is your personal software stash. Later, we’ll make it easy for other machines to install from here.


Step 4: Create the Packages.gz File

Now, let’s make the file that tells apt what packages are in your repo.

Run:

cd /opt/debian-repo/bullseye
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

Let me explain:

  • dpkg-scanpackages . /dev/null looks in the current folder.
  • gzip -9c compresses the package list.
  • > Packages.gz saves it.

After this, the folder should have:

  • Your .deb files
  • A Packages.gz file

That’s your repo, almost ready to use.


Quick Checklist Before Moving On

  • Do you have .deb files in the folder?
  • Did Packages.gz get created without errors?
  • Is dpkg-dev installed?

If all yes, let’s make it shareable.


Step 5: Share the Repository with Apache

To let other machines access the repo, we’ll use Apache.

First, install Apache:

sudo apt install apache2

Then create a symlink (shortcut) from your repo folder to Apache’s web root:

sudo ln -s /opt/debian-repo /var/www/html/debian-repo

Now, restart Apache:

sudo systemctl restart apache2

Visit http://your-server-ip/debian-repo/bullseye/ in a browser. You should see your .deb files and Packages.gz.

This means it’s working.


Step 6: Add the Repo to Another Machine

Now let’s use the repo on another Debian system.

Edit or create this file:

sudo nano /etc/apt/sources.list.d/localrepo.list

Add this line:

deb [trusted=yes] http://your-server-ip/debian-repo/bullseye ./

Replace your-server-ip with your server’s IP address.

Save the file and run:

sudo apt update

Now your system sees your local repo.

You can try installing one of the packages:

sudo apt install mypackage

It will install from your local folder—not the internet.


Three Simple Troubleshooting Tips

  • Getting 403 or 404 errors? Check folder permissions and make sure Apache is running.
  • Packages not showing up? Make sure Packages.gz is created and up-to-date.
  • APT says package not found? Double-check the .deb filename and try running apt-cache search.

Optional: Automate Package Index Updates

Every time you add a new .deb file, you need to update Packages.gz.

You can make it easier with a script:

#!/bin/bash
cd /opt/debian-repo/bullseye
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz

Save this as update-repo.sh, make it executable:

chmod +x update-repo.sh

Then run it each time you add new files.


Three Situations Where a Local Repo Helps

  • Offline networks: When machines aren’t allowed online for security.
  • Slow or expensive internet: You save data and time.
  • Custom apps: Share in-house software without uploading it to the cloud.

Conclusion

Setting up a local repository on Debian isn’t hard. Once you understand the pieces—folders, Apache, and package indexes—it all comes together.

I’ve used this in home labs, schools, and small offices. It’s saved me bandwidth and made my updates a lot faster.

If you’re still downloading packages one-by-one on each machine, maybe it’s time to try this. It takes an hour to set up, but pays off every time you install or update something.

Have you built your own repo yet? Or are you planning to? Let me know what you’d like to automate next—maybe syncing with USB or using rsync.

 

 

Leave a Reply