An introduction to Debian packages.

Posted by Steve on Fri 1 Oct 2004 at 10:19

Debian software is typically installed from binary packages, (which means that you dont need to use a compiler to build them yourself), which are downloaded from the Debian package archives.

Most complex pieces of software have dependencies, that is software which they rely upon.

For example if you wish to install a image viewing program to display programs will probably discover this relies on some libraries that understand specific images, such as JPG files and PNG files.

Thankfully the Debian apt command handles this for you, painlessly.

There are two levels to working with packages, at the low level there is the dpkg command, this will allow you to install a single binary package, list packages installed, and remove a single package.

At a level above that there is the apt-get command. This manages installing packages, and any required dependencies.

The apt-get command reads lists of all the software available within the archive, and allows you to install any of the avaiable software with only a simple command.

In order to query the Debian package repository it needs to know which distribution you're running, and where to download this information from. This information is configured in the file /etc/apt/sources.list.

On a Debian stable box your sources file will look something like this:


#
#  Stable sources
#

deb http://ftp.us.debian.org/debian stable main non-free contrib
deb http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free



#
#  Security updates
#
deb http://security.debian.org/ stable/updates main contrib non-free

The unstable distribution will look something like this:

# Unstable
deb http://ftp.us.debian.org/debian unstable main non-free contrib
deb http://non-us.debian.org/debian-non-US unstable/non-US main contrib non-free

deb-src http://ftp.us.debian.org/debian unstable main non-free contrib

(The big difference here is that the word stable has been replaced with unstable, and there is no security line).

If you have a sources file setup already you are half ready to install new software.

First of all you should run, as root, the following command. This will download the lists of software available, and all the dependency information:

root@ids:~# apt-get update

The update means that the tool will go and download the updated package lists.

Once this has completed you can install a package named 'less' by running:

root@ids:~# apt-get install less

This will inform you what it is going to do, and then promptly download the package and install it:

root@ids:~# apt-get install less
Reading Package Lists... Done
Building Dependency Tree... Done
The following NEW packages will be installed:
  less
0 upgraded, 1 newly installed, 0 to remove and 80 not upgraded.
Need to get 0B/102kB of archives.
After unpacking 262kB of additional disk space will be used.
Selecting previously deselected package less.
(Reading database ... 25436 files and directories currently installed.)
Unpacking less (from .../archives/less_382-1_i386.deb) ...
Setting up less (382-1) ...

Once it's completed you'll see that it has installed the file 'less_382-1_i386.deb' (in this case) and you can verify this using the dpkg command which we briefly mentioned earlier.

root@ids:~# dpkg --list less
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
ii  less           382-1          Pager program similar to more

Here we've asked dpkg to '--list' the package less, on the far left we see 'ii' which means the package is installed.

One thing that makes Debian such a simple system to maintain is that it's possible to upgrade all the packages on your machine with any new versions which have become available with a simple command.

Using the lists of packages which apt-get downloaded earlier it can examine your system to see which packages you have installed locally, and upgrade each one that has a newer version available.

This is done by running 'apt-get upgrade'.

root@earth:~# apt-get upgrade
Reading Package Lists... Done
Building Dependency Tree... Done
0 packages upgraded, 0 newly installed, 0 to remove and 0  not upgraded

In this case there are no new packages available, so nothing happened. Had there been new packages to install you would have been prompted to confirm that you wished to upgrade (and shown a list of the packages it was going to modify).

If we wish to remove the package we can type dpkg --remove less, which will remove the package. This may not be possible if another package relies upon it. In this case we're safe so it will be removed:

root@ids:~# dpkg --remove less
(Reading database ... 25453 files and directories currently installed.)
Removing less ...

Some packages, such as lynx, will install configuration files. If you wish these to be removed along with the package you can use the more brutal '--purge' flag:

root@ids:/etc# dpkg --purge less
(Reading database ... 25436 files and directories currently installed.)
Removing less ...
Purging configuration files for less ...

That's a brief summery of working with packages on Debian systems, to recap we've seen:

  • apt-get update
    • Update the list of available packages on your system
  • apt-get install 'name of package'
    • Install the given package, and any required dependencies
  • apt-get upgrade
    • Update all the packages on your system for which there is a newer version available
  • dpkg --list 'name of package'
    • Show the state of the package given
  • dpkg --remove 'name of package'
    • Remove the package named.
  • dpkg --purge 'name of package'
    • Remove the given package and remove all configuration files, etc.

 

 


Posted by Anonymous (192.195.xx.xx) on Mon 13 Jun 2005 at 01:30
If the output of dpkg --list is crowded in gnome-terminal or konsole then enter the following before the dpkg command:
export COLS=200

[ Parent | Reply to this comment ]

Posted by hardik (61.95.xx.xx) on Tue 30 Aug 2005 at 06:37
There is also a nice utility from dpkg is with -C option for auding the .deb packages. It will Searches for packages that have been installed only partially on your system. And then dpkg will suggest what to do with that packages.

You can use "dpkg-reconfigure packagename" to reconfigure the package.


With Cheers,
Hardik Dalwadi.

[ Parent | Reply to this comment ]

Posted by zberg (62.255.xx.xx) on Mon 14 Nov 2005 at 22:27
yeah, discovering dpkg-reconfigure changed my life

[ Parent | Reply to this comment ]

Posted by Anonymous (82.182.xx.xx) on Sat 13 May 2006 at 16:18
Hi! I like the explanation very much. Tank you.

[ Parent | Reply to this comment ]

Posted by Anonymous (68.149.xx.xx) on Sun 25 Jun 2006 at 01:54
Hi, I need help with a tough problem. Can I use apt-get to UPGRADE only a specific package, and also UPGRADE all required dependencies at the same time? Particularly, I'm trying to upgrade the k3b in my system, I tried to run "apt-get install k3b", it tells me that there are a lot of dependencies unsatisfied because the versions of those dependencies already in the system are too old, and that's all, it stops.

Is there any way to make apt-get to try to solve the dependencies by also UPGRADING the dependencies?

Thank you

[ Parent | Reply to this comment ]

Posted by Anonymous (217.194.xx.xx) on Mon 26 Jun 2006 at 10:26
Have you tried
apt-get remove k3b; apt-get install k3b

[ Parent | Reply to this comment ]

Posted by Anonymous (68.149.xx.xx) on Sat 1 Jul 2006 at 02:35
Thank you for your reply.

Actually, I was trying to update Knoppix 3.6 (pretty old...) by updating the k3b package, because when trying to overburn a DVD it was hanging.
So I tried "apt-get install k3b", but after a big list of unsatisfied dependencies it stopped, telling me to try "apt-get -f install" to solve the unsatisfied dependencies. Now, I admit, I didn't read the whole message the first time, when I posted this message. Afterwards, reading it, I noticed it was all about ALREADY EXISTING unsatisfied dependencies in the system, because that's how the distribution came.
So I tried "apt-get -f install" (with no parameters) and apt-get downloaded all required packages and installed them and fixed all broken dependencies.
After that, I was able to install k3b in a snap, also using k3b.
I have to say, this is the first time I used apt-get, but it's a GREAT tool!! Those who made it should get a NOBEL prize in computers, it saves you SO MUCH HASSLE!!! To me it was like discovering the wheel.
By the way, even after updating dvd+rw-tools and k3b, the problem persists, k3b still hangs when I try to overburn DVD's, but anyway, I'll find a way around it, I hope.

[ Parent | Reply to this comment ]

Posted by Anonymous (217.127.xx.xx) on Wed 13 Sep 2006 at 20:12
I have the opposite problem. I want to do an update with the exception of a single package. Is this possible?

[ Parent | Reply to this comment ]

Posted by Anonymous (81.119.xx.xx) on Wed 18 Oct 2006 at 13:06
Yep you have to pin the package and the system will mantain it to the *previous* version
touch /etc/apt/preferences
vim /etc/apt/preferences

Package: <package name>
Pin: <version of package> (Wild carda are allowed nice feature)
Pin-Priority: tell how to match rules of Package and Pin.

Take a look at http://www.debian.org/doc/manuals/apt-howto/ch-apt-get.en.html

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 528 votes ~ 7 comments )