Tag Archives: apt

Apt-Cacher: Revisited

I’m sure that I’ve mentioned a number of times that the bandwidth speeds at my house are pretty horrible. It is very frustrating to have such a limited pipe considering the amount of work I do that requires bandwidth. Based on this limitation I regularly come up with ways to conserve and cache. One of these methods (which I have blogged about in the past) is apt-cacher.

Apt-Cacher is a method by which you can centrally cache and share packages already stored within your network. It also allows the option of caching any downloaded packages in the future. This allows me to download a package once and transparently share it with an unlimited number of machines within my network. This way I only use my Lanwidth (LAN-bandwidth), and not my limited WAN connection.

Apt-Cacher can be installed and configured network wide in five simple steps. These steps are:

  • Install
  • Autostart daemon
  • Configure ACL
  • Import current packages
  • Configure Clients

To be honest, the first four steps are finished in just a few minutes. The last step of configuring your clients can take longer. The amount of time depends on how many clients you have.

Install

To install apt-cacher simply install the package (or click the link below):

sudo aptitude install apt-cacher

Autostart daemon

If you want the apt-cacher daemon to autostart at boot you’ll need to change a single value in the config:

sudo sed -i.orig 's/AUTOSTART=0/AUTOSTART=1/' /etc/default/apt-cacher

sudo /etc/init.d/apt-cacher restart

Configure ACL

This step is optional. By default apt-cacher will allow access to any IP. If you would like to limit access to your cache from a specific subnet or other specific addresses you’ll need to change the values for allowed_hosts and denied_hosts in the /etc/apt-cacher/apt-cacher.conf.

Import current packages

You’ll likely want to import the current packages that you have in your machine’s package cache. This can be done using the command:

sudo /usr/share/apt-cacher/apt-cacher-import.pl -s /var/cache/apt/archives/

At this point this machine will have the ability to share any packages that it has previously downloaded as well as any package that it (or any client) will download in the future. The only requirement to begin using this cache throughout your network is configuring the clients to use it.

Configure Clients

To configure your clients to use your cache you can simply add a line to your apt.conf file, telling the client to use the cache server. To do this add the following line to your /etc/apt/apt.conf file, replacing the IP with your own:

Acquire::http::Proxy "http://192.168.0.30:3142"

You’re now done. As long as your apt-cacher is accessible your client will look there for cached packages.

If anyone knows of a method to allow for multiple proxy entries I would be very interested. For example, if this were configured on a laptop and the apt-cacher were not accessible, I would like the client to transparently try the next entry in a list. This is something available in many other package managers, I would hope Debian based distributions would support the same.

Add PPA Key To Your Apt Keyring

I know many of you use Launchpad’s “Personal Package Archive” for updated and beta packages. I have about a half-dozen configured on my machine to give me the latest and greatest of my favorite applications. The one problem with a PPA though is that the packages can’t be verified when downloaded because you don’t have the GPG imported into your Apt Keyring. The following command is a template that you can use to import whatever PPA based keys you have warnings on:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <key id>

You can gather the <key id> in the output of:

sudo apt-get update

You should see the warnings, along with the key id at the bottom of the output.

For each GPG key that you get a warning on, run the command above, and you’ll stop seeing the warnings. You will have imported that team/project’s GPG key into your keyring, considering them trusted.

AptURL : Web Based Package Installation

Some of you may have seen some recent posts around the Ubuntu Planet about the new AptURL project that is default in Ubuntu 7.10 “Gutsy”. I wanted to make a few comments about it myself after tinkering with it a little. I think the project and idea is pretty cool and I hope it sees some more use.

I may be updating my blog in the future to take advantage of AptURL. I suppose to maintain backwards compatibility I’ll need to use both, but we may begin seeing tutorials along these lines:

Example…

Installing non-free codec pack

sudo aptitude install ubuntu-restricted-extras

For those using Ubuntu 7.10 you should be able to simply click the link and the package should prompt for installation. If it does not try installing the apturl package. Those still using previous versions will still need to type the command on the command line.

Does anyone have any thoughts on seeing this on the blog moving forward? Good? Bad? Indifferent? I think it may make some tutorials a bit simpler for some users.

Getting the source package with aptitude?

Ever since I learned about the benefits of aptitude vs apt-get I’ve switched over. It’s been great and I’m sure I’ve preached about the benefits before (/me does some digging and pulls up links) here.

Well, I ran into something yesterday that I haven’t been able to solve with aptitude. Is it possible to pull down the source code from the deb-src repository via aptitude and not apt-get source?

I’d sure appreciate if anyone can tell me a way.

Save Bandwidth With Multiple Machines with Apt-Cacher : Ubuntu (6.10)

Over the holidays I was visiting my parents and helping my brother with his Ubuntu system. One of the biggest drawbacks of heading up that way for a visit is leaving the fiber-optic comforts of home and heading up to DSL villa. I swear its like rewinding a decade and hearing the hellish dial-up noises all over again!

In any event, I was helping my brother update his Ubuntu machine and was getting tired of seeing the estimated download time hover around 18hrs! It was about that time that I got to thinking… “my laptop is up to date. There should be a way for him to simply download the updates from my machine over the LAN.” After some Google magic I came across Apt-Cacher and a cure was found!

“Apt-cacher performs caching of .deb packages which have been downloaded by local users. When a package is requested, the cache checks whether it already has the latest version, in which case it sends the package to the user immediately. If not, it downloads the package while streaming it to the user at the same time. A local copy is then kept for use by other users.”

Apt-Cacher will allow you to centrally cache any updates or installed packages on a central machine and help you save bandwidth. No matter if you have two Ubuntu machines or twenty, as far as your bandwidth is concerned your ISP will only think you have one! Below are steps for setting up Apt-Cacher.

First, of course, we’ll need to install it (it only needs to be installed on one central machine).

sudo aptitude install apt-cacher

To test that it is installed correctly you can try visiting the address below:

http://[localhost]:3142/ or http://[LOCAL.IP]:3142/

If you see the Apt-Cacher page the server end of things are setup. There are a few other things you can tweak, and you’ll probably want to take a look at a few configuration options such as allowed_hosts and denied_hosts. You can edit these settings in the /etc/apt-cacher/apt-cacher.conf

allowed_hosts=192.168.0.0/24 (to allow all local machines)

denied_hosts=

You also need to configure Apt-Cacher to “go live” so you’ll need to change one more option in another file. Simply change the AUTOSTART within /etc/default/apt-cacher from 0 to 1.

sudo vim /etc/default/apt-cacher

AUTOSTART=0

to

AUTOSTART=1

And one last option to run on the server machine is to import any existing .deb packages on that machine into the Apt-Cache database. Use the following command to import your current cache:

sudo /usr/share/apt-cacher/apt-cacher-import.pl /var/cache/apt/archives

After you’ve made any of these changes to the apt-cacher.conf file you’ll need to restart Apt-Cacher by using:

sudo /etc/init.d/apt-cacher restart

The next thing to do is simply point your other local machines to this central machine instead of the central repositories. You’ll want to first backup your original sources.list using the command:

sudo cp /etc/apt/sources.list /etc/apt/sources.list-backup

And then simply edit your the file to look something more like:

deb http://[LOCAL.IP]:3142/archive.ubuntu.com/ubuntu/ edgy main restricted
deb http://[LOCAL.IP]:3142/archive.ubuntu.com/ubuntu/ edgy universe multiverse
deb http://[LOCAL.IP]:3142/archive.ubuntu.com/ubuntu/ edgy-updates main restricted
deb http://[LOCAL.IP]:3142/archive.ubuntu.com/ubuntu/ edgy-updates universe multiverse
deb http://[LOCAL.IP]:3142/archive.ubuntu.com/ubuntu/ edgy-security main restricted
deb http://[LOCAL.IP]:3142/archive.ubuntu.com/ubuntu/ edgy-security universe multiverse
You’ll notice that I’ve simply prefixed archive.ubuntu.com with the local network address of the machine running Apt-Cacher and specified the default port. This is a broken down version of a sources.list for the sake of space. From there on everything should run the same as normal.

Now you can give things a spin by checking for updates as normal.

sudo aptitude update && sudo aptitude upgrade

Everything should appear as normal. Remember you can also continue to use this to install individual packages on each machine. Not all the machines need to carry the same either. Whatever is requested from any machine will be checked on the Apt-Cacher server and retrieved if it isn’t yet available.

For more information on using Apt-Cacher you might be interested in these pages:

How to setup a repository cache with Apt-Cacher

Nick Andrew’s Apt-Cacher Page

Debian Universe Apt-Cacher Information

Package Management with APT : Ubuntu (all versions)

If you’ve read any of my previous posts you know they all take advantage of APT to install or upgrade packages. If you’ve spent more than a few hours using Ubuntu you’ve probably taken advantage of APT. Anytime you add, remove or upgrade part of your system you’re using APT. I thought I would take a minute today to explain a few more features of APT that you might not be familiar with.

First of all you might have noticed that all of my tutorials use the command aptitude instead of apt-get. The reason for this, from my understanding (and perhaps some of you can address this in a bit more detail) that aptitude handles dependencies better than apt-get. For example, if you install package X which also has dependencies Y and Z either of these (apt-get or aptitude) will bring in the dependencies, but only aptitude will remove those unneeded dependencies when you later decide to remove package X.

Outside of this difference between the two commands the options are almost all the same. I thought I would go over these in a little more detail for those of you that aren’t familiar.

update – this option used with aptitude or apt-get will retrieve the latest versions of packages from the update servers. You should check for updates periodically (normally your system should check automagically from time to time)

search [keyword] – this option will allow you to search for packages by name or description. Do you want to find a package that offers feature [keyword] or [keyword]? Simply use aptitude search [keyword] (or with apt-get use apt-cache search [keyword]) and a list of packages will be retrieved matching your search.

show [package] – this option will show you more detail about the package. File sizes, extended descriptions, dependencies and maintainer information. This is useful when you want to know more about your package. As above if you’re using apt-get the command would be apt-cache show [package].
install [package] – this option is pretty straight forward. If you want to install [package] use the command and your package will be retrieved and installed for you. If you’ve ever installed anything from the command line or used any of my previous tutorials you’ve definitely used this option.

remove / remove –purge [package] – this option will let you remove a package that you had previously installed. Using the remove option your system will uninstall whatever package you want (see above on using aptitude for dependency removal). Using the –purge option will also remove any configuration files that your program had included. If you know you are never using the program again and can safely purge any trace of it, you can use the –purge option. If you might be back (it happens) the config files might come in handy later.

upgrade - this option will allow you to upgrade your system. After running update (see above) using the upgrade command will get your system up to date on anything new waiting on the central package repositories. You should regularly run update and upgrade to keep your system up to date.

dist-upgrade – this option will do a complete upgrade of your system. Often a package will be updated but the new version also depends on additional packages. To make sure you are completely updated you’ll want to also include this in combination with upgrade. A complete set of upgrade steps would be to use update followed by upgrade and then dist-upgrade.

autoclean – this option cleans your system from previous upgrades. The APT system will download the latest package when it upgrades your system. If you have upgraded a package two or three times since originally installing you might then have three versions of that package in your system cache. Using autoclean tells your system to remove the previous, now unneeded packages. This is also a good idea after running upgrade and dist-upgrade.

These might seem like a lot to handle or remember. It really isn’t much once you’ve gone through the steps once or twice. You might be interested in seeing a previous post to automate the updating. One that will update, upgrade, dist-upgrade, and autoclean your system using one simple command.
Ooh, and for a little bit of fun try this: apt-get moo

technorati tags:, , , ,

How to add extra repositories : Ubuntu (5.10 / 6.06.1 / 6.10)

This post is something that may be fairly basic for many of you, but extremely helpful for anyone new to using Ubuntu. In an attempt to be as comprehensive as I can with my tutorials I wanted to go back to the basics.

Ubuntu (and Debian) use a package management system called APT. This system uses a list of repositories to access updates and install programs specifically designed for your distribution and version. This system is generally more secure and more stable than other methods. Mainly for the reasons that access into these public repositories is kept very strict, and each package is thouroughly tested before it is included. Packages are also digitally signed for verification and security.
This tutorial will outline how to manually edit and update your repository source list to access whatever program you might need.

As usual, before editing any system file you will want to back it up. You should backup your sources.list file using the following command at a terminal:

sudo cp /etc/apt/sources.list /etc/apt/sources.list-backup

Below is an example of a sources list for Ubuntu including main, restricted, security, universe and multiverse. This will give you access to everything in the official Ubuntu repositories (over 20,000 packages)

# Ubuntu supported packages
deb http://archive.ubuntu.com/ubuntu edgy main restricted
deb http://archive.ubuntu.com/ubuntu edgy-updates main restricted
deb http://security.ubuntu.com/ubuntu edgy-security main restricted

# Ubuntu community supported packages
deb http://archive.ubuntu.com/ubuntu edgy universe multiverse
deb http://archive.ubuntu.com/ubuntu edgy-updates universe multiverse
deb http://security.ubuntu.com/ubuntu edgy-security universe multiverse

To update your current sources.list to this expanded list (by default the universe and multiverse are not activated) run the following command:

sudo gedit /etc/apt/sources.list

..and overwrite the contents of the existing file with the example above. Note: the example above does not include the “source” for these packages. Normal users generally don’t make use of the source for the packages. Unless you know you are going to be manually compiling and editing the source for the programs you don’t need to worry about it. If you do want the source simply add a duplicate line using the prefix deb-src instead of deb.
After you’ve made changes to your sources.list file you can update to the latest list using the command:

sudo aptitude update

At that point you can request any available updates using the command:

sudo aptitude upgrade

At this point the system will compare any current versions you have and install any upgrades that are available on the public repositories. Your system will automagically check for updates normally on a daily basis.
EDIT: To create a customized sources.list file based on your interests or needs you can visit the Source-O-Matic published by the Ubuntu Netherlands Team. (note: the source-o-matic currently only supports up to Dapper and NOT edgy.)

You may also be interested in my recent post, Seveas Repository.

technorati tags:, , , , , , , , ,