Skip to main content

Ever wonder what apt-get does underneath?

Shower thoughts

This question came from when I was showering one day: What does apt-get or apt or yum, pacman does underneath to install all those programs that you have specified?

Well you're in luck because the past me have did a good research on how it works. Here is the jist of it:

  • When you are issuing the command apt-get update it will look into your /etc/apt/source.list file, this file contains a list of repository files. You will see lines like

    deb http://us.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

    This indicates a Package file that apt-get update will be fetching. For example, http://security.ubuntu.com/ubuntu/dists/jammy/main/binary-amd64/Packages.gz for the Jammy release of Ubuntu. It will store these files for each line of repository that you have into /var/lib/apt/lists.

    If you decompress the file, you will see metadata of each package that you can install via apt-get, for example, neofetch. The metadata contains information such as where you can find the .deb file from the relative URL. It also list out the dependencies that apt-get need to install in order run the program.

  • Finally, when you issue the apt-get install command, it will search for the program that you have specified and if it is found in one of those source list, it will go to the relative URL and fetch the .deb. .deb files are just pre-compiled binary and it will just install that into your system.

note the actual installation process is done by dpkg underneath for Debian based distro. apt-get is really just a wrapped on top of dpkg for fetching those pre-compiled binaries forĀ dpkg to install.

So under the hood package managers like apt-get is looking up list of packages to know where to find their pre-compiled binary. When you ask to install it, it will go and fetch the pre-compiled binary and install it into your system.

Pre-compiled vs compiling from source

Compiling from source is what it sounds like. You have the source code, for example, bunch of .c files, and you will compile it into a program and install it into your system yourself.

Pre-compiled binary is a binary executable that is compiled to work on most environments, although it might not be most optimized for your targeted system, but it will work.

When you compile from source, you get more options because you are able to change the flags to do different type of optimization, and the compiler will optimize instructions specifically for your system. Pre-compiled binary don't get to enjoy those type of optimization but the ease of use is a trade-off. You don't have to compile anything because you just need to download them and it will work for your system.

.gz .xz, .tar.gz files

To decompress .gz file use the tool gzip

To decompress .xz file use the tool unxz

To decompress .tar.gz file use tar