Skip to content

Instantly share code, notes, and snippets.

@Aetherinox
Forked from ikbelkirasan/host_apt_repo_on_github.md
Last active October 8, 2023 10:37
Show Gist options
  • Save Aetherinox/5740e512c0d7b76b5e40008c1f8d7c57 to your computer and use it in GitHub Desktop.
Save Aetherinox/5740e512c0d7b76b5e40008c1f8d7c57 to your computer and use it in GitHub Desktop.
Github: Host Apt Repo

Host an APT repository on Github

This guide will help you host an APT repository on Github.

Prerequisites

You need to install the following packages.

  • reprepro
    $ sudo apt install -y reprepro

Setup

Create a new folder containing the repo.

# Change <repo-name> to the repo folder
$ mkdir -p <repo-name>/{conf,incoming}

# Create the distributions file
$ cat <<EOF >> conf/distributions
Origin: Foo
Label: Foo Github
Suite: stable
Codename: bionic
Architectures: amd64
Components: main
Description: Debian x64 github repository
EOF

Add the GPG key to Github

Get the key using the following command, then copy the output and add it to GPG keys in Github settings.

# List secret keys on your machine and copy your key id
$ gpg --list-secret-keys --keyid-format LONG

# Export the key and copy the output
$ gpg --armor --export <key-id>

Add the repository to APT

Open the file /etc/apt/sources.list and add the following line. Make sure to fill in the fields <repo-owner>, <repo-name>, <Codename> and <Component> with your own values.

deb [arch=amd64] https://raw.githubusercontent.com/<repo-owner>/<repo-name>/master <Codename> <Component>

Or run this command:

$ sudo add-apt-repository -y "deb [arch=amd64] https://raw.githubusercontent.com/<repo-owner>/<repo-name>/master <Codename> <Component>"

Add the key to APT using apt-key.

$ gpg --armor --export <key-id> | sudo apt-key add -

Add a deb package to the repo

First, copy the deb file to incoming folder.

$ cd <repo-name>

# You may to change the section, component and priority to the values you want.

# The deb file should follow this format: <package-name>_<version>_<architecture>.deb

$ reprepro -V \
    --section utils \
    --component main \
    --priority 0 \
    includedeb bionic incoming/<package-name>_<version>_<architecture>.deb

Push the repo to Github

Push your repository to Github then update your APT cache.

$ sudo apt update

# Now you can try to install a package from your repository :)
$ sudo apt install <package-name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment