Set up a Debian Private Repository with Reprepro

In this post, we will set up a minimal Debian private repository with Reprepro and Apache. To keep everything simple, we will not use GPG keys.

1 Set up Apache Web Server

To serve the package files over HTTP, we need a Web Server. Here we use Apache.

1.1 Install Apache

As root, run

1
$ apt install apache2

1.2 Configure Apache

Assume we will set up a repository in /var/www/repos/apt/debian.

As root, edit /etc/apache2/sites-enabled/000-default.conf configuration file.

1
$ nano /etc/apache2/sites-enabled/000-default.conf

Add the following configuration to the <VirtualHost> block,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<Directory /var/www/repos/ >
# We want the user to be able to browse the directory manually
Options Indexes FollowSymLinks Multiviews
Order allow,deny
Allow from all
</Directory>

# This syntax supports several repositories, e.g. one for Debian, one for Ubuntu.
# Replace * with debian, if you intend to support one distribution only.
<Directory "/var/www/repos/apt/*/db/">
Order deny,allow
Deny from all
</Directory>

<Directory "/var/www/repos/apt/*/conf/">
Order deny,allow
Deny from all
</Directory>

<Directory "/var/www/repos/apt/*/incoming/">
Order allow,deny
Deny from all
</Directory>

and change DocumentRoot.

1
DocumentRoot /var/www/repos

Now save the file with Ctrl+O Enter and exit the editor with Ctrl+X.

Test the syntax of the configuration file with

1
$ apache2ctl configtest

You should see Syntax OK. If not, check the configuration file you just edit.

1.3 Reload Apache

As root, reload Apache to apply the configuration.

1
$ systemctl reload apache2

2 Set up Reprepro

2.1 Install Reprepro

As root, run

1
$ apt install reprepro

2.2 Configure Reprepro

Create the configuration directory with

1
2
$ mkdir -p /var/www/repos/apt/debian/conf
$ cd /var/www/repos/apt/debian/conf

Create and edit file distributions with

1
$ nano distributions

and copy-paste the following contents

1
2
3
4
5
6
Origin: Your project name
Label: Your project name
Codename: buster
Architectures: amd64
Components: main
Description: Apt repository for project x

Change the relevant fields based on your needs. Save the file and exit the editor.

If you are working with Loongson CPUs, change the architecture amd64 to mips64el.


Create and edit file options with

1
$ nano options

and copy-paste the following contents

1
2
verbose
basedir /var/www/repos/apt/debian

We also need to set up the environment variable REPREPRO_BASE_DIR so that reprepro knows our base directory is /var/www/repos/apt/debian.

Edit your ~/.bashrc if you are using Bash, or ~/.zshrc if you are using Zsh. Add the following line to the tail of the file.

1
export REPREPRO_BASE_DIR=/var/www/repos/apt/debian

To apply the change, run

1
2
$ source ~/.bashrc      # for Bash
$ source ~/.zshrc # for Zsh

Now your reprepro is ready to go!

3 Add the first package to the repo

Suppose we have a package socat_1.7.3.2-2_mips64el.deb.

Add it to the repo with

1
$ reprepro includedeb buster socat_1.7.3.2-2_mips64el.deb

Open your web browser, visit http://localhost/apt/debian/pool/main , you should see your new package.

4 Install your new package

Now the repository server is set up, you can now install packages. You might wish switch to another machine.

4.1 Add your private source to /etc/apt/sources.list.d

1
$ echo 'deb http://repo-server/repos/apt/debian buster main' > /etc/apt/sources.list.d/myrepo.list

Replace repo-server with the IP address (or the hostname) of the repository server you just set up.

4.2 Prioritize the private source

Create and edit a apt preferences configuration file with

1
$ nano /etc/apt/preferences.d/99-myrepo

and copy-paste the following contents

1
2
3
Package: *
Pin: origin repo-server
Pin-Priority: 900

Replace repo-server with the IP address you used in step 4.1.

Ideally, I think the repository prioritiy should be set by the server instead of the client, but I can’t figure out where to set it in a reprepro setup. Please let me know if you have an idea.

4.3 Update apt package list

Update the package list with

1
$ apt -o "Acquire::AllowInsecureRepositories=true" update

Note the option -o "Acquire::AllowInsecureRepositories=true". In our setup, since we do not sign the repository (and packages in it), we need to explicitly allow it.

4.4 Verify the new priority works

Run

1
$ apt-cache policy

Check if the your new repository precedes all other sources except /var/lib/dpkg/status.

A valid example output may look like this:

1
2
3
4
5
6
7
8
9
 100 /var/lib/dpkg/status
release a=now
900 http://repo-server/apt/debian buster/main mips64el Packages < our private repository
release o=whatever,n=buster,l=whatever,c=main,b=mips64el
origin repo-server
500 http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates/main mips64el Packages < default repositories in the system
release v=10,o=Debian,a=stable,n=buster,l=Debian-Security,c=main,b=mips64el
origin mirrors.tuna.tsinghua.edu.cn
...

4.5 Install the test package

Install the test package socat with

1
$ apt install socat

During the installation, apt will warn us (again) of the insecurity of the package we are going to install. Enter y to proceed anyway.

1
2
3
WARNING: The following packages cannot be authenticated!
socat
Install these packages without verification? [y/N]

Now the socat from your own repository is ready to go!

Reference

https://wiki.debian.org/DebianRepository/SetupWithReprepro