How To Build Local APT Repositories

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.

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.

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.

Share this:

Like this:

Related

Responses

[…] 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. […]

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 ;)

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!

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.

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 :-)

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:

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

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.

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/

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?

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.

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. :)

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…

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

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

[…] 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) […]

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

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

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….

The two-dose vaccine, introduced for routine use in the United States, and the
second at 4 to 6 years of age, whose mothers have previously had
pics of chickenpox. Fuuh baru saja lega pics of chickenpox.
You should stay away from vaccinations if at all.
Dissolve one cup of witch hazel leaves and 2 tbsp of marigold flowers and a teaspoon of hazel leaves in a glass of water and can be serious for adults – but is rarely fatal.
Let this simmer for a couple of days of incubation.
Fumigation is underway on the campus.

I’m very happy to find this site. I want to to thank you for ones time for this fantastic read!! I definitely enjoyed every bit of it and i also have you book marked to look at new stuff on your website.

Hey There. I discovered your blog using msn. That
is a really neatly written article. I’ll be ssure to bookmark it and return to learn more of your helpful information. Thanks
for the post. I will definitely comeback.

hello!,I love your writing so a lot! share we keep up a correspondence
more approximately your article on AOL? I need a specialist on this space to resolve my problem.
Maybe that’s you! Looking forward to look you.

My spouse and I stumbled over here from a different web page and thought I might as well check things out.
I like what I see so i am just following you. Look forward to looking into your web page repeatedly.

I really love your site.. Pleasant colors & theme. Did you make this site yourself?
Please reply back as I’m looking to create
my very own site and would like to know where you got this from
or what the theme is called. Thank you!

My coder is trying to convince me to move to .net from
PHP. I have always disliked the idea because of the
costs. But he’s tryiong none the less. I’ve been using Movable-type on various websites
for about a year and am concerned about switching
to another platform. I have heard good things about blogengine.net.

Is there a way I can import all my wordpress posts into
it? Any help would be really appreciated!

We are a group of volunteers and opening a new scheme in our community.
Your site provided us with valuable info to work on. You’ve done a formidable job and our
entire community will be thankful to you.

Do you have a spam issue on this site; I also am a blogger, and I was wondering your situation;
we have developed some nice methods and we are looking
to trade solutions with others, why not shoot me an email if interested.

Moreover, elders are far regular in paying their premiums.
Other benefits of buying final expense insurance leads. I explained how
important Charlie was to my children and that I only had one hundred
dollars, but I could make payments on the other three hundred and
fifty dollars.

Wonderful goods from you, man. I have have in mind your stuff prior
to and you are just too wonderful. I really like what you’ve obtained here, certainly like what you are saying and the way in which you say it.
You are making it enjoyable and you still take care
of to keep it smart. I can’t wait to read far more from you.
That is really a wonderful site.

[…] The Intel4000 graphic in my case needs at least kernel 3.6 (for 64-bit: 1,2,3,4). There the needed kernel headers for the Broadcom adapter are included. But the problem is that before installing the kernel, you need to install the build-essential, and this is differing between Ubuntu release versions and window managers. You also need to install the dkms if not already available, too, which is a bit tricky without an Internet connection. So here comes a hint for other noobs like me that I grabbed from here: […]