Software & AppsOperating SystemLinux

How To Set Up an APT Repository

Ubuntu 14

Creating your own APT repository can be an efficient way to distribute software within your organization or to the public. This article will guide you through the process of setting up an APT repository from scratch.

Quick Answer

Setting up an APT repository involves several steps, including generating signing keys, creating the repository directory, creating an update script, and providing instructions for users. It is not possible to provide a quick answer to this topic as it requires detailed instructions and explanations.

What is an APT Repository?

An APT repository is a network server or a local directory containing deb packages and metadata files that are readable by the APT tools. It allows for easy software distribution and installation on Debian and Ubuntu systems.


Before starting, ensure you have the following:

  • A server or local machine running Debian or Ubuntu.
  • Basic understanding of Linux terminal commands.
  • Sudo or root access to your server or local machine.

Step 1: Generate Signing Keys

The first step in setting up an APT repository is to generate a pair of signing keys. This ensures that the packages and metadata in your repository can be verified as authentic.

Use the gpg command to generate a new key pair:

gpg --gen-key

During key generation, you will be asked for a name and email address, which will be associated with the key. You will also be asked to enter a passphrase.

Once the key pair has been generated, export the public key:

gpg --armor --export your-email > public.key

Replace “your-email” with the email address you used during key generation. This will create a file named public.key containing your public key.

Step 2: Create the Repository Directory

Create a directory where you will store your .deb packages:

mkdir /var/www/html/apt-repo

This will create a new directory at /var/www/html/apt-repo.

Step 3: Create an Update Script

Next, we need to create a script that will rebuild the APT repository whenever new packages are added. Here’s an example of what this script might look like:


# Set the necessary environment variables
export GNUPGHOME="/root/.gnupg"

# Import the GPG keys
gpg --import /path/to/secret.key

# Symlink the .deb files
ln -s /path/to/debs/*.deb /var/www/html/apt-repo

# Build the Packages file
dpkg-scanpackages /var/www/html/apt-repo /dev/null > /var/www/html/apt-repo/Packages

# Create a signed Release file
apt-ftparchive release /var/www/html/apt-repo > /var/www/html/apt-repo/Release
gpg --yes -abs -o /var/www/html/apt-repo/Release.gpg -b /var/www/html/apt-repo/Release

This script does several things:

  • Sets the GNUPGHOME environment variable to the location of your GPG keyring.
  • Imports your secret key.
  • Creates symbolic links to your .deb files in the repository directory.
  • Uses dpkg-scanpackages to generate a Packages file, which contains metadata about the packages in your repository.
  • Uses apt-ftparchive to generate a Release file, which contains metadata about the repository itself. This file is then signed using your secret key.

Step 4: Provide Instructions for Users

Finally, you will need to provide instructions for your users on how to add the repository to their sources.list file and import your public key. Here’s an example:

echo 'deb /' | sudo tee -a /etc/apt/sources.list
wget -O - | sudo apt-key add -

Replace “” with the domain name or IP address of your server.


Setting up an APT repository involves several steps, but the result is a powerful tool for distributing software. Remember to keep your secret key secure, and regularly update your repository with new packages. With your own APT repository, you can manage software distribution in a more controlled and efficient manner.

Can I set up an APT repository on a server running a different Linux distribution?

No, APT repositories are specifically designed for Debian and Ubuntu systems. If you are using a different Linux distribution, you will need to use a different package management system.

Can I use a different tool instead of `gpg` to generate signing keys?

While gpg is the most commonly used tool for generating signing keys, you can use other tools such as openssl if you prefer. However, the process may vary, so it’s recommended to refer to the documentation of the specific tool you choose to use.

Do I need to manually run the update script every time I add new packages to the repository?

Yes, you will need to run the update script whenever you add new packages to the repository. This ensures that the Packages and Release files are updated with the latest metadata. You can automate this process by scheduling the script to run periodically using tools like cron.

Can I host my APT repository on a cloud-based server?

Yes, you can host your APT repository on a cloud-based server. As long as the server is running Debian or Ubuntu, you can follow the same steps to set up the repository. Just make sure you have the necessary access and permissions to create directories and execute commands on the server.

Can I customize the directory structure of my APT repository?

Yes, you can customize the directory structure of your APT repository. The example in this article uses the /var/www/html/apt-repo directory, but you can choose a different location if desired. Just make sure to update the paths in the update script accordingly.

Leave a Comment

Your email address will not be published. Required fields are marked *