The simplest way to locally distribute Debian packages

The simplest way to locally distribute Debian packages

How to have a simple Debian repository to offer your packages.

Sometime, you will need to install some packages on a remote machine without internet access.

Or, you want to distribute your own Debian packages in your environment.

The simplest way to do it is to setup your own local repository.

Requirements

  • python3

  • dpkg-scanpackages: sudo apt-get install dpkg-dev

  • gzip: sudo apt-get install gzip

Create your repository folder structure

You can customize it, but I will keep my structure quick and simple:

mkdir ~/my_repo/debian

Then go to that directory:

cd my_repo

Add your .deb files to the debian folder

cp my_deb_thing.deb my_deb_thing2.deb my_repo/debian

In this example, 2 have put 2 packages for kibana and elasticsearch to the debian folder.

Create Packages.gz file

You'll need to do this every time you add/update a .deb.

dpkg-scanpackages debian /dev/null | gzip -9c > debian/Packages.gz

You'll get an output similar to:

dpkg-scanpackages will create indices for your packages so Debian package manager can read it.

Run a webserver to host it

Any webserver will do, simply used Python.

python3 -m http.server 9000

The port can be change accordingly.

Configure client machines to point to your debian repository

Add to client machine /etc/apt/sources.list

deb [trusted=yes]http://your-server-ip:9000debian/

Note that the packages will be non authenticated, so if you want to stop having warnings you'll need to add the [trusted=yes]

When update, we will see client getting packages:

Then client can install package using APT package manager, just like a normal packages.

Conclusion

In this post, I show you a quick and easy way to host your own APT repo.

However, for the sake of simplicity, I didn't use any proper webserver; and I didn't secure the distribution process.

There are more secure method like apt-mirror or rerepo and add your own GPG key.

Did you find this article valuable?

Support Nguyen Duc Chinh by becoming a sponsor. Any amount is appreciated!