August 22, 2019

What happens when ... you run $ apt-get install <>

If you have tried any Linux based system, chances are that you would have run

apt-get install <>

atleast once.

This would have been followed by you going to have coffee (or tea?) and taking a break while your terminal is spewing stuff like -

Windows-Installation

I think we need to talk about a few things before we proceed.

  1. I know the gif shows a windows terminal.
  2. It doesn’t show apt-get install.
  3. I spent a lot of time procastinating and trying to find the perfect gif. It doesn’t exist. But a lot of cat gifs were watched during the process.
  4. You get the idea.

apt-get is a command line interface for managing packages provided by Debian. It is used to add and remove software packages.

What is a package

We need step in to a time machine and head back to the age when software was predominantly distributed via mailing lists and FTP. One would have to download the source code, look for a ./configure that would install the required depedencies and then use the Makefile to compile and install the software.

Makes you want to give npm a nice hug and say “Thank you” doesn’t it?

This was a cumbersome process to install and play around with software. Packages were designed to battle this complexity. Packages are prebuilt binaries that one could install using a tool called package manager. The early versions of these package managers only handled the binaries and the dependencies of a binary were not part of the downloaded artifcat. Later versions of package managers included dependency resolution which made it easy and removed the need to lookup depedencies before downloading software. Package management systems usually go hand in hand with a software repository which is a collection of packages or meta infromation about packages. Package managers usually search repositories to find software and their depedencies.

What is a Debian Package

Debian GNU/Linux is a particular distribution of the Linux operating system, and numerous packages that run on it.

The Debian Project was created by Ian Murdock and I love the fact that the project name is a contraction of the names of Debra and Ian Murdock.

With Linux having multiple flavours, each of these distributions have their own sofware repositories, package managers and package structures. Most notable of these are -

  1. .deb packages which are used in Ubuntu, Linux Mint and Debian
  2. .rpm used by RedHat, Fedora and SUSE.

.deb package mainly contains the following components

  1. debian-binary - Contains information regarding version of debian package.
  2. control archive - This archive contains meta information about the package.
  3. data archive - Contains the actual software.

So what is apt-get

The .deb packages were initially managed by a tool called dpkg. dpkg was built to download pre-built binaries and it had capabilities to check if depedenices are matched but did not have the ability to resolve dependencies for the user. Later, a new debian project, Advanced Package Tool (APT) was started which would take care of depedency resolution aswell and works with dpkg.

APT includes a collection of tools that deal with package management and also command line programs that use the library. apt-get and apt-cache are the most commonly used command line programs. Popularly, apt and the command line tools are reffered to as a front-end to dpkg. i.e means by which users can communicate with dpkg.

APT uses /etc/apt/sources.list as a list of sources from which packages can be downloaded. An example of a source list is as follows -

deb http://deb.debian.org/debian buster main
deb-src http://deb.debian.org/debian buster main

deb http://deb.debian.org/debian-security/ buster/updates main
deb-src http://deb.debian.org/debian-security/ buster/updates main

deb http://deb.debian.org/debian buster-updates main
deb-src http://deb.debian.org/debian buster-updates main

You can add or remove sources and after modifiying the source list and apt-get is made aware of new locations to search for packages.

There quite a few front-ends for apt that are available now, some also have a GUI apart from having a command-line interface like Synaptic and aptitude. Historically, apt-get was only designed as a test front-end for libapt-pkg but it was exteremly succesful and popular.

apptitude

synaptic

Summary

When you run

    sudo apt-get install <package-name>
  1. apt-get searches for the package in the software repository.
  2. Checks dependencies.
  3. Installs dependencies.
  4. Installs the software package.

A more detailed look into the lookup and dependency resolution process is available here - https://debian-handbook.info/browse/stable/sect.apt-get.html

References

  1. https://opensource.com/article/18/7/evolution-package-managers

  2. https://blog.tidelift.com/a-brief-history-of-package-management

  3. https://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html

  4. https://en.wikipedia.org/wiki/Deb_(file_format)

  5. https://debian-handbook.info/browse/stable/sect.apt-get.html