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: