1. Open terminal.
Install dpkg-dev ,apache2 and apt-mirror
$ sudo su
$ apt-get update && apt-get upgrade
$ apt-get install dpkg-dev apache2 apt-mirror
2. Create a directory where you will keep your packages. For this example, we’ll use /usr/local/mydebs.
$ mkdir -p /usr/local/mydebs
3. Now copy your packages into the directory you’ve just created.
$ rsync -truv /var/cache/apt/archives/* /usr/local/mydebs
#tip: you can place that command on crontab to sync every week
4. The Script update-mydebs
It’s a simple three liner:
$ mkdir -p ~/bin
$ . ~/.bashrc
$ nano update-mydebs
copy the below code.
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
Next, make the script executable:
$ chmod u+x ~/bin/update-mydebs
How the script works:
dpkg-scanpackages looks at all the packages in mydebs, and the output is compressed and written to a file (Packages.gz) that apt-get update can read (see below for a reference that explains this in excruciating detail). /dev/null is an empty file; it is a substitute for an override file which holds some additional information about the packages, which in this case is not really needed. See deb-override(5) if you want to know about it.
5. Update sources.list
$ echo "deb file:/usr/local/mydebs ./" | tee -a /etc/apt/sources.list
6. Whenever you put a new deb in the mydebs directory, run
$ apt-get update
Now your local packages can be manipulated with Synaptic, aptitude and the apt commands: apt-get, apt-cache, etc. When you attempt to apt-get install, any dependencies will be resolved for you, as long as they can be met.
Badly made packages will probably fail, but you won’t have endured dpkg hell.
7. Configuring apt-mirror
$ cp /etc/apt/mirror.list /etc/apt/mirror.list.orig
$ cp /etc/apt/sources.list /etc/apt/sources.list.orig
$ cp /etc/cron/apt-mirror /etc/cron/apt-mirror.orig
$ cp /var/spool/apt-mirror/var/postmirror.sh /var/spool/apt-mirror/var/postmirror.sh.orig
Now edit the files.
$ echo "deb file:/usr/local/mydebs ./" | tee -a /etc/apt/mirror.list
$ echo "clean deb file:/usr/local/mydebs ./" | tee -a /etc/apt/mirror.list
You can also remove or comment out the lines dealing with source code if you don’t expect to need or use them. You can always add repositories later if you want. The time it takes to populate your mirror after adding something is less than the initial population of your mirror, so you can start with the minimum and add more later as the need arises.
8. Now you can run apt-mirror for the first time.
You might want to wait on this step since it will take a while for your mirror to build, overnight for example(depending on your internet speed).
You’ll see it working, but it will appear slow.
Once the mirror is populated, link the repository to the web server:
9. Linking repository to Webserver(apache2)
ln -s /var/spool/apt-mirror/mirror/archive.ubuntu.com/ubuntu /var/www/
ln -s /var/spool/apt-mirror/mirror/security.ubuntu.com/ubuntu /var/www/
ln -s /usr/local/mydebs /var/www/
Finally, make apt-mirror an automated task:(Not really necessary)
remove the comment from the last line.
$ nano /etc/cron.d/apt-mirror
10. Moving to the client side:
Edit the sources.list file that will be used to access the mirror.
$ sudo nano /etc/apt/sources.list
The example below assumes using the mirror from the computer that hosts it.
Using it from other computers on the network simply requires changing the IP address from 172.x.30.100 to whatever IP address is assigned to the mirror host(Server).
deb http://172.x.30.100/debs ./
deb http://172.x.30.100/debs /
deb http://172.x.30.100/ubuntu precise main restricted universe multiverse
deb http://172.x.30.100/ubuntu precise-updates main restricted universe multiverse
deb http://172.x.30.100/ubuntu precise-security main restricted universe multiverse
deb http://172.x.30.100/security precise main restricted universe multiverse
deb http://172.x.30.100/security precise-updates main restricted universe multiverse
deb http://172.x.30.100/security precise-security main restricted universe multiverse
11. Update the source.list, run
$ sudo su
$ apt-get update & apt-get upgrade