A few days ago i had to create an internal repository for some deb packages. As there weren’t so many packages, i didn’t need to create a huge repository, like the official ones, so, after a little research, i managed to get it working, and that is what i will explain here, how to create a simple repository for deb packages.
We’ll need this packages before we can continue:
- apt-utils
- dpkg-dev
In debian-like systems you can install it by executing:
1
| # aptitude install apt-utils dpkg-dev |
And now the steps:
1 – Select the directory in which the repository will be:
I recommend you to use a direcotory in /var/www , like /var/www/repository, making it possible for everyone to see and access it without the need change apache configurations, but for this you’ll have to have apache installed.
For this tutorial we will take /var/www/repository as our repository directory.
1
| # mkdir /var/www/repository |
2 – Move packages to the repository directory:
Move all deb packages you want to be in the repository to the repository directory, in our case: /var/www/repository.
1
| # mv *.deb /var/www/repository |
3 – Create index files (Packages and Sources):
These files tell apt wich packages are available in the repository, their version, author and other informations. These files must be in the repository directory.
To create them you’ll have to run:
1 2 3 4
| # dpkg-scanpackages /var/www/repository > /var/www/repository/Packages
# dpkg-scansources /var/www/repository > /var/www/repository/Sources
# dpkg-scanpackages /var/www/repository /dev/null | gzip -9c > /var/www/repository/Packages.gz
# dpkg-scansources /var/www/repository /dev/null | gzip -9c > /var/www/repository/Sources.gz |
What there command do:
The first two commands scan the given directory for, repectively, .deb files and .dsc files and save their informations in, respectively, Packages and Sources.
The two last commands do the same thing, but instead of saving the files’ informations in a text file, it compresses the files’ informations and save it to a .gz file, which apt will also look for.
For more information about these commands check manpages for each one.
4 – Add repository uri to /var/apt/sources.list:
Now that you have a repository running you’ll, probably, want to access it, right?! To do that you’ll have to edit /etc/apt/sources.list .
If you want to access the repository from the same machine you’ll need to add the following lines:
1 2 3 4
| # For binary files repository:
deb file:///var/www/ repository/
# For source files repository:
deb-src file:///var/www/ repository/ |
If you want other machines to access it you’ll have to have those machines in the same network and add the following lines in their /var/apt/sources.list file:
1 2 3 4
| # For binary files repository:
deb http://repository's.machine.ip/ repository/
# For source files repository:
deb-src http://repository's.machine.ip/ repository/ |
5 – Check if the repository is up:
Now run:
and see if everything is ok.
And that’s it, you should have your repository running.
TIP:
You can make a script to automatize the creation of index files, all you have to do is create a script in the /usr/bin/ directory and add the command lines for the dpkg-scanpackages and dpkg-scansources commands:
1 2 3 4 5 6 7
| # cd /usr/bin
# echo "#!/bin/bash \
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz \
dpkg-scansources . /dev/null | gzip -9c > Sources.gz \
dpkg-scanpackages . > Packages \
dpkg-scansources . > Sources" > createrepo
# chmod +x createrepo |
The script above will scan for packages and source files in the directory it’s going to be executed and you’ll have to run it as root, you could add ‘sudo’ before each dpkg-scan command so you could run it as a normal user, but it would ask you for the sudo password as well.
This tutorial was based on:
- http://ubuntuforums.org/showthread.php?t=42862
- http://www.debian.org/doc/manuals/repository-howto/repository-howto.en.html
:wq!