UPDATE: This post has been updated to include a section on accessing downloaded packages through a local intranet.Some obsolete info has also been deleted. The techniques detailed here have been tested on all versions of Ubuntu and will probably work on other debian-based linux distributions.
I was going through my /var/cache/apt/archives folder the other day and I thought to myself, “So will I have to re-download all these packages if I do a clean install? Internet access is not cheap here in Ghana and the speed is nothing to write home about… I’m talking about you, Vodafone!! It’d be cool to build my own APT repository with the 3000+ packages in my local cache.” The only snag was I didn’t know how to do it. So I went hunting on google and it turned out a lot has been published on this topic. I found it all rather confusing, mostly geeks talking to other geeks in geekish, so I decided to write my own how-to for my much simpler mind.
If your roaring to go and know what you’re doing, skip down to the summary. If you want to take things slow however, read on. Okay, enough talking already, let’s get our hands dirty…
- Create folders for the package files you plan to keep in your repository. Here is an example: in your home folder, create a new folder called repository in which you will keep all your downloaded packages. If you plan to burn the package files onto a CD, I suggest you create separate folders for each disk. The naming is up to you – disk_1, disk_2, etc (I’ll assume this naming convention throughout the rest of the tutorial). This is just to ensure that you use the next folder once your cache reaches the size of a CD (usually 700MB). If you are using a local hard drive or a DVD, you obviously have higher limits to keep in mind. If you do not plan to create a CD/DVD, you may simply dump all the files in the repository folder.
- The next step is to copy all your deb files (those files that end with .deb) to the repository folder(s). Open Nautilus, navigate to /var/cache/apt/archives and copy all the deb files to the appropriate folder(s). For instance, /home/<username>/repository/disk_1 – keep an eye on the size of the folders. To do it in the terminal:
cp /var/cache/apt/archives/*.deb ~/repository/disk_1
- Remember to replace <username> with your real username.
- If you have many files, it may take quite a while so be patient.
- Change into your repository folder:
cd ~/repository/disk_1/
- Now run the following command to create the Packages.gz file that is needed to for Synaptic to “see” your repository:
sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
- I suggest you copy and paste this to avoid any typos.
- Please note that every time you add any more .deb files to this folder, you have to create a new Packages.gz file using the above command before the new file(s) will show up in Synaptic (or Aptitude).
- Be sure to install the build-essential package (sudo apt-get install build-essential) before running the above command.
There are several ways of using your newly created repository.
I) Keeping the files on a local hard disk
- Edit your /etc/apt/sources.list file like so:
gksudo gedit /etc/apt/sources.list
- And insert this on a new line (preferably the first):
deb file:/home/<username>/repository/disk_1/ /
- Remember to replace <username> with your real username.
- KDE SC users, replace gksudo gedit with kdesudo kate
- Reload your package index like this:
sudo apt-get update
II) Setting up a repo on your intranet (using a web server)
This method is more useful if you want access to your repo from other machines on your network.
- First, follow method I) above and install the apache web server like so:
- sudo apt-get install apache2
- Let’s say the ip address of the web server (and the machine with the debian packages) is 192.168.4.100. We need to tell the apache server on 192.168.4.100 where to find the downloaded files:
sudo ln -s /home/<username>/repository/disk_1/ /var/www/repo
- If you’ve not tinkered with apache’s configuration files, /var/www/ is usually the default virtual host.
- Right, now let’s make sure another machine on the network… say 192.168.4.101, can see the repo on 192.168.4.100. Edit the sources.list file on 192.168.4.101 like so:
gksudo gedit /etc/apt/sources.list
- And insert the following on a new line:
- Update 192.168.4.101′s package index:
sudo aptitude update
- I almost always forget to open up port 80 in my firewall. If you’re like me and only allow connections to port 80 on a per-machine basis, you know what to do when you start getting connection refused errors.
II) Using a CD/DVD as a repository:
- Burn the repository folder onto a CD/DVD
- With the disc loaded in your drive, fire up Synaptic and click through the menus like this:
Edit –> Add CD Rom.
- You will be asked to type in a description for the disc; type in anything, for instance: Offline Repository Disk1.
- Click Ok.
- Go to /var/cache/apt/archives and copy your debian packages to a folder of your choice, for example, /home/<username>/repository/
- Change into the repository directory
cd ~/repository
- and generate a Packages.gz file like this:
sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
Make sure build-essential is installed (sudo aptitude install build-essential) before you run the above command.
- Add the following line to your sources.list file (/etc/apt/sources.list)
deb file:/home/<username>/repository/ /
- Remember to replace <username> with your real username
- Reload your package index like this:
sudo apt-get update
I know, I know… APTonCD does most of this in a simple intuitive GUI but it forces you to use a CD/DVD approach. You’ll still have to do some tweaking if you want to use any other method… which reminds me, I need to write an APTonCD post.


[...] By localized I don’t mean ‘on a server in the same country’ although that would be a start. Imean something more along the lines of a CD/DVD/External hard drive set up as a package repository. Currently I create custom repositories myself following this guide by another Linux Accra member. I’d love for there to be a faster way to do this though. Maybe I should look into creating a tool to automate the custom repository creation. Or does one exist already? I just wish there was some awareness on the part of the people who are trying to promote open source in developing countries that bandwidth can be a huge issue here and can affect how ‘free’ something is vs. readily available pirated software. [...]
By: Linux in areas of low bandwidth « Ramblings of an African Geek on November 14, 2006
at 6:04 pm
Even here in rural USA bandwidth is slow, thanks for the info.
By: Fred on December 30, 2006
at 1:17 pm
Fred,
I’m glad my how-to was of any help
By: odzangba on January 7, 2007
at 11:57 pm
Hey your info on How to build local APT repositories has made me had bad headache. Nothing works right on Ubuntu Dapper.
You might need to make some correction aboutpackages directories:
## My local repository
deb file: /home/“username”/repository/disk_1/
The right thing is;
deb file: ///home/“username”/repository disk_1/
Huh… agree???
By: goutzilla on January 8, 2007
at 12:31 pm
Event the
## My local repository
deb file: /home/“username”/repository disk_1/
After googling here and there, eventually I found the working repository setting.
http://www.ubuntuforums.org/archive/index.php/t-7455.html
I have proved it, and it just woks so well.
1) Create a dir in your home (ex. /home/pinco/Ubuntu-repository)
2) Generate Package file: dpkg-scanpackages . /dev/null > Packages
3) Insert in sources.list the correctly path like this:
deb file:/home/pinco/Ubuntu-repository ./
4) sudo apt-get update
By: goutzilla on January 8, 2007
at 12:53 pm
goutzilla,
The line in my how-to is correct:
## My local repository
deb file: /home/“username”/repository/disk_1 /
You forgot to insert a spcae between the “disk_1″ and the final “/”. That’s why I encouraged you to copy and paste to avoid typos.
I’m glad you finally got it to work though.
Cheers
By: odzangba on January 10, 2007
at 12:04 pm
hey dude thnx a lot its really good support for me but i think there is something missing, i.e. we also have to copy repository files to /var/cache/apt/archives
P.S. ive written a script for u guys help enjoy
#dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
cp sources.list /etc/apt/
cp -pr repository/ /root/
cp repository/* /var/cache/apt/archives/
aptitude update
echo ‘***********successfull***********’
By: umair syed on June 21, 2007
at 9:29 am
[...] repository server is done. If you want more information, I found this page very helpful. Now make sure apache is running and we can move on to the final step, making your [...]
By: Assay Depot Development Blog » Build Your Own Deb File and Repository Server on July 9, 2007
at 11:56 pm
This is so cool. I always thought you could use apt with local deb files. I never thought it would be this easy. Far better and quicker than redownloading EVERYTHING! This is especially useful for me. I gathered my /var/cache/apt/archives from my first ubuntu install. And then I took my archives from the cache that was backed up in my other linux installs (kubuntu, knoppix). I stored it all on my external usb harddrive and now I can install everything that I love. Far better than the tie it takes to download games and things like that. LONG LIVE OPEN SOURCE SOFTWARE
thx for this tutorial!
By: Durell Wilson on July 23, 2007
at 3:58 am
This is very useful. It saves time and in your case money. I’ll just like to add a little thing I had to do before I was able to do this. I am on Ubuntu 7.10 Gutsy, however the same applies to Ubuntu 7.04 Feisty and maybe other versions. Ubuntu doesn’t have the command: ‘dpkg-scanpackages’ installed. So just run this:
$ sudo apt-get install dpkg-dev
Just type in your password and stuff, and let it install. That’ll get you dpkg-scanpackages and more dpkg utilities. I hope I helped. Also I know on the Gutsy LiveCD has the dpkg-dev and apt-get will ask you to insert the install cd. Other versions of Ubuntu I am not sure.
By: Problems in Ubuntu? on August 19, 2007
at 5:19 pm
It’s probably a better idea to install the build-essential package as one of the first things you do after installing ubuntu. Just do
sudo apt-get install build-essential
That will save you a lot of headache later on.
Ciao,
Odzangba
By: odzangba on August 19, 2007
at 7:28 pm
I have an offline machine without a DVD-ROM but with content of 4 DVDs of packages on its hdd, and I’ve been wondering how to make synaptic see those packages. Hope, your post will help.
By: xemul on August 30, 2007
at 4:33 pm
Hi Xemul,
Good luck with the offline repository. Post back here if you run into any problems.
Cheers,
Odzangba
By: odzangba on September 4, 2007
at 1:49 pm
its very cool viva forums.
By: ilir on October 9, 2007
at 9:21 am
was looking for exactly this info. beautifully explained. thanks!
By: nalin9487 on October 27, 2007
at 1:43 pm
Have fun with it.
By: odzangba on October 29, 2007
at 7:44 pm
Nice explication for creating his own repository.
But, one question : there is none gpg authentification for this repository, and then, each time that an install is realised (with synaptic, or apt-get), an error message appear.
Do you know how to solve this problem ?
By: eric from France on March 16, 2008
at 2:37 pm
hey thanks a lot … thanks a lot now I can backup and share my downloaded packages
By: pratik on March 20, 2008
at 9:17 am
Hey. This is a great tutorial. Thanks. Do you know the Nonetdebs project? http://nonetdebs.homeip.net/. This is great if you have a laptop with no internet connection and want to install things on it. I have put my repository on an usb memory stick
By: kitabu on April 29, 2008
at 5:51 am
nice nice neat
jut tell me will it work with RPMs and synaptic?
By: Stefan on April 30, 2008
at 10:26 pm
of course if all deb instances are replaced with rpm
By: Stefan on April 30, 2008
at 10:30 pm
i don’t think this will work for rpm.
createrepo
should work and is the better way, not to mix things up (go the way your distribution wants you to go)
(createrepo must be installed ;o]). if successful you should get the metadata “repodata” in .
besides this command also works as well:
dpkg-scanpackages ./ /dev/null > Packages
it doesn’t need to be gzipped as long as it’s local.
(be aware to do all as root, otherwise it could end in an local exploitable point if the package can be written by the world [for k/ubuntu users sudo all]l)
greetz.
By: none on June 25, 2008
at 2:06 pm
@umair syed
you should put
#!/bin/sh
as first line. oh and you should just echo “succsessful” if there’s really no error, so test it. keep things clear.
furthermore wtf shall that cp sources.list /etc/apt, you won’t have a sources.list but a Packages.gz argh, there you go:
#!/bin/sh
touch error_of_the_script_xxyyzz
dpkg-scanpackages ./ /dev/null | gzip -9c > Packages.gz 2> error_of_the_script_xxyyzz
sizeoferrorfile=$(du error_of_the_script_xxyyzz | cut -b 1)
if [ $sizeoferrorfile -eq 0 ]
then
echo -ne “\ndeb file:$(pwd)” // >> /etc/apt/sources.list
echo ‘***********successfull***********’
else
echo ‘ERROR: ‘
cat error_of_the_script_xxyyzz
fi
rm error_of_the_script_xxyyzz
#if you want the following command to be also executed just remove the #
#apt-get update
you could place it in /usr/sbin
it has the be run in the desired directory.
don’t forget to “chmod +x script_name.sh” to make it executable.
when moving the packages directory you have to edit your /etc/apt/sources.list
GreetZ.
By: none on June 25, 2008
at 3:36 pm
This is close to what Im tryin gto find. Simply put Im trying to find a totally offline way of using a 120 gb usb hard drive as my software sources for all of my repo disks. The DVD’s are frankly getting worn out. I need a way to store my repo DVD’s in one place so the computer can look in one place while Im updating things, or installing software while mobile and not online.
Please email me asap before my disks finally wear out! LOL thanks!
By: yaughn on July 11, 2008
at 8:12 am
Great guide, thanks a lot
I have been doing several Debian installs on virtual machines recently and this saved a lot of bandwidth! I now also have a ‘base’ repository on a USB key so getting from a fresh install to a finished system is much faster now.
o/
By: Pete on July 17, 2008
at 9:04 pm
thanks guys..
i was looking for this..
By: Aruna on August 11, 2008
at 12:49 pm
Thanks HEAPS for this post. I was stuck trying to do this for hours… still learning.
http://ubuntuforums.org/showthread.php?p=5653789#post5653789
By: sparklyprgs on August 24, 2008
at 10:51 am
You may want to try apt-cacher.
By: Hristo on September 27, 2008
at 6:23 pm
Thanks Dear. I was looking for this info. for a long time. I don’t have an internet connection in my pc. But I can download .deb packages from another computer. So this will be helpfull.
By: Arun on October 22, 2008
at 10:48 am
If i wanted to backup my apt Repository to a different directory on my computer, what path would i set in the sources.list file.
By: Ricardo on December 1, 2008
at 7:19 am
Ricardo, I’m not sure I understand but you would use the path to the backup location in your sources.list file.
By: odzangba on December 2, 2008
at 10:01 am
thanks for the info.
but i think aptoncd is better then whole of this procedure
By: sumit on December 4, 2008
at 10:32 pm
odzangba could i take the repo folder i made and just put it in a repo directory online like my website and have a deb http://mysite.com/repo/ would this work for a online repo to add to source list and install software?
By: mike on December 23, 2008
at 11:08 pm
were is the package zip file located when it done being created?
By: mikmikee on December 24, 2008
at 1:37 am
it in the /home/your-name/ folder this is were your package.gz file will be once its created.
LOL i found it haha!
By: mike on December 24, 2008
at 1:40 am
Glad you found it
And yes could put the repo online and it would work.
By: odzangba on December 24, 2008
at 8:58 am
Hi
I like your page and the way your explain things.
I’m a newbie, so some stupid questions.
I have three computers, all of them are old 800 Mhz.
Sorry this is the luxury I have. I have a very slow internet connection. I ISP provides me with an IP.
So basically I have all my Ubuntu’s on 192.168.1.X network and I connected them all to a switch.
1) Could you explain how I can convert one Ubuntu into a repo for my other two.
2) Force the other two to use the local repo rather than download from the internet.
3) What should the sources.list look like on the local as well as the remote.
Eagerly waiting for your help.
By: koolneze on January 25, 2009
at 11:16 pm
Hi koolneze, it seems during one of my late night clean ups, I inadvertently removed the section on using the mirror over a local network… I don’t know what I was thinking.
Luckily, I have a similar post here http://odzangba.wordpress.com/2007/12/24/use-apt-mirror-to-create-your-own-ubuntu-mirror/
Scroll down to the “Method Two” section and follow the instructions. Essentially, you’ll have to install a web server (apache) on one of the machines and tell the others to only download packages from it. Good luck.
By: Odzangba on January 26, 2009
at 12:32 pm
Here is some info i thought you would like if you want to know how repos work and how to make one on line.
http://www.jejik.com/articles/2006/09/setting_up_and_managing_an_apt_repository_with_reprepro/
By: divine-shadow on January 28, 2009
at 6:06 am
I was wailting for this a long time.thanks for your help.i want to know “do it works if i dont copy the deb files in /var/cache/apt/archive/” ?
By: Anwar on March 21, 2009
at 10:59 am
[...] [upmod] [downmod] How to build local APT repositories « Odzangba Kafui Dake’s Blog (odzangba.wordpress.com) 0 points posted 1 year, 1 month ago by trshant tags 4mdelicious howto [...]
By: Tagz | "How to build local APT repositories « Odzangba Kafui Dake’s Blog" | Comments on May 16, 2009
at 4:54 pm
Thanks for this info, it help me a lot
By: Yudi Lee on November 3, 2009
at 8:29 am
There is a GUI that will do the same thing and is very easy.
It is in the repositories called “APTONCD”. Check it out.
But thanks for all the work and help.. been there..
Joey
By: Joey on December 30, 2009
at 1:53 am
how can i upload my debian packages into a local repository??????????
Please help
By: himanshu on February 4, 2010
at 4:01 pm
Thank for this excellent article!!!
It helped me very much,as I’am a Linux beginner. Now I can organize my .deb-files in an own repository and have also all the luxary with Synaptics.
Greetings from Germany,
where it is very, very cold at the moment.
By: Chis on February 17, 2010
at 7:03 pm
Works great.
Very usefull to upgrade or install a new package in a Debian distro from an other Debian distro where this package is already installed.
Thank’s Odzangba.
By: Plume on April 3, 2010
at 11:36 am
[...] google and there are lots of resources/how to available, see below I found these two interesting: http://odzangba.wordpress.com/2006/1…-repositories/ http://cutecomputer.wordpress.com/20…y-for-apt-get/ I haven't test these but seems easy to [...]
By: APT Repository mirroring on April 14, 2010
at 6:58 am
Great info! Thanks
By: Menno on April 21, 2010
at 2:24 pm
HI,
Thank you for the information.
But
How to access the repository across intranet. The repository which you said will work fine in local machine. But I want to create one common repository for my Intranet?
can you help me with this regard?
Thanks in advance.
Raja
By: raja on June 3, 2010
at 12:23 pm
Awesome!
Exactly what i was searching for!
By: kauboy on June 10, 2010
at 5:04 pm
Hi. Thank you so much. It’s very clear and comprehensive and saves so much time. But I’ve got a bit of problem when try to update another machine. If it have a internet conenction via the local network, it still downloads from the internet instead of downloading from the local network… unless I delet everything else in sources.list and keep the local server as the only source.. Could I change the priority of the downloading source? I’ve put the deb http://192.168.4.100/repo/ / line as the first line…
By: Yutian on July 16, 2010
at 3:26 pm
Yutian, that’s because your local repo is not signed. APT will prefer signed or trusted sources to unsigned ones. There’s a tutorial on the ubuntu forums that explains how to do this: http://tinyurl.com/33pv56p
I’ll have to update my tutorial to include this. I hope this helps
By: Odzangba on July 17, 2010
at 4:35 am
Thanks for the how-to. It helped me a lot to save my ISP bandwidth.
By: Rezaul Karim on November 23, 2010
at 1:05 pm
I followed the instructions to the leter, and I’m getting the following ignores, no matter what I do:
Ign file: Release.gpg
Ign file:/home/vmc/xyz/ Translation-en_US
Ign file: Release
Ign file: Packages
Ign file: Packages
By: Vern on March 3, 2011
at 3:06 am
Works! Thanks!
By: Pablo on April 23, 2011
at 8:14 pm
Excellent, clear summary – thank you!
GJ
By: Graham Jones on June 17, 2011
at 8:46 pm
Nice Greetings from kerala…
By: sandeep krishnan on June 29, 2011
at 10:32 am
[...] that we do not have every user downloading all updates again over the internet. I read this about building a local APT directory, and that sounds very useful. However, my question is: if our server (with Ubuntu Server Edition) [...]
By: Ubuntu: Best structure for local repositories - Admins Goodies on August 9, 2011
at 10:01 am
My portable programm can make Ubuntu repository mirror, calculate total downloading size, remove old packages from repository.
Picture:
http://mozgoed-mgoy.narod.ru/ubuntu/screen.jpg
Programm link:
http://mozgoed-mgoy.narod.ru/ubuntu/ubuntu-repository.zip
Required:
Windows 2000, Windows XP – .Net Framework 2.0
Windows Vista, Windows 7 – Nothing
Ubuntu 10.10 – Mono project packages. Programm can be executed from terminal “mono ubuntu-repository.exe”
Let’s work with visual tools! =)
By: Mozgoed on September 7, 2011
at 10:08 am
I tried this on debian 6.0 and it just worked
# local repository
deb file:// /usr/local/local_debs/
By: unsigned_nerd on November 6, 2011
at 7:25 am
Thanks it is very clear.
It also works with synaptic package manager
Here is an example in Ubuntu 10.04 x86-64 also called amd64
Settings->Software Sources->Other Software
[+ADD]
then in the apt line field
deb file:///home/username/debianpkgs lucid main
where /home/username/debianpkgs is the directory with the .deb files
now execute the command above:
sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
Packages.gz must be placed in
/home/username/debianpkgs/dists/lucid/main/binary-amd64
By: anonymous on February 24, 2012
at 9:09 pm
Hi, I followed this tutorial to setup the local
repository, but, I got errors when I ran
% sudo apt-get update
Here are what I did:
1. Created Packages.gz and copied to USB stick
2. Copied Packages.gz from USB stick to
my new computer under
/home/username/repository
3. Added the following line on the top
of /etc/apt/source.list
deb file:///home/username/repository /
4. Ran % sudo apt-get update generated
these errors:
Err http://sg.archive.ubuntu.com natty InRelease
Err http://extras.ubuntu.com natty Release.gpg
Could not resolve ‘extras.ubuntu.com’
Ign file: InRelease
Ign file: Release.gpg
Err http://sg.archive.ubuntu.com natty-updates Release.gpg
Could not resolve ‘sg.archive.ubuntu.com’
Any ideas? Thanks a lot!
By: Danette on February 28, 2012
at 8:08 am
Thanks OJ
By: Julius on October 9, 2012
at 8:27 am
Thankyou for your post Odzangba, very useful.
Also I suggest FreeFileSync or similar. As I dont keep packages on /var/cahe/apt/archives I use ffs to update my backup
From Argentia
By: Fernando on February 20, 2013
at 5:21 pm
Go through the worksheets attached to the W-4. You can claim 2 for yourself and your daughter, then
can also claim one or two more, depending on your income, for the child tax credit, so can probably claim
up to 4 if you want to without owing at tax time.
Depending on your income, you might also be eligible for an Earned Income Credit which would come in
your refund.. . Child support is not deductible to
the payer or taxable to the person receiving it, so has
nothing to do with your taxes and is not reported on your return.
. . If you’ll post again listing your total expected income for the year, what you’ve had withheld so far, and the amount of child care costs you
expect to pay for the year, someone can give you
a closer answer on what you might get back as a refund.
. . Just to give an example, if your income for the year will be around $20,000, you’d be likely to get back whatever was withheld, plus an Earned Income Credit of a little less than $2000. . . Sounds like you are a very busy person. Good luck all around….
By: Mark Lewis on June 18, 2013
at 2:17 am