Ubuntu

Where does apt-get install packages to?

Whether you are a Linux veteran or just starting with Linux, you must have used apt-get or seen it being used somewhere. It is the primary way to install packages and dependencies on Ubuntu. In simpler terms, apt-get is the go-to of every Linux user when looking to set up software on their computer. This gives rise to a new question – where does apt-get install these packages to? Where do the files go, and how can one access them? In this guide, we will find out the answers to these questions.

Ubuntu Filesystem Layout

Before we get into the technicalities of the matter, let us start by acquiring a basic understanding of the Filesystem Hierarchy Standard, shortly known as FHS. All Linux distributions get their directory structure and contents from Filesystem Hierarchy Standard. We will briefly go over some parts that are crucial to understanding where apt-get install packages are and why so.

FHS is not considered to be some authority on directory structure and contents for absolutely every Linux distribution, but it is generally the most common standard of file layout. All directories and files in FHS appear under ‘/’ – the root directory. Let’s take a look at some commonly used directories.

  • /bin directory holds the primary command binaries.
  • /dev directory contains device files.
  • /etc directory has host-specific configuration files.
  • /home folder contains the user’s personal settings and saved files.

A non-profit organization known as Linux Foundation maintains the Filesystem Hierarchy Standard, and the last update (version 3.0) was made on June 3, 2015.

Now that we have gotten a better understanding of how the general Linux filesystem is structured and how it operates, we are ready to learn how apt-get makes use of this very structure to install packages and dependencies.

Package Management

All operating systems and Linux distributions come with a package manager. These package managers are responsible for installing and removing software from the computer and maintaining them. They give the user more control over what kind of programs they wish to run on the system and make their installation possible.

In Ubuntu (and Debian), dpkg is the package manager that most people use. You can manage packages with .deb extensions through dpkg. Discussing this utility is pertinent to our subject since we will be using it to find apt-get installs packages. “Aptitude” is the more user-friendly way to use dpkg as it provides a front-end to the users. Let us look at how dpkg works in Ubuntu, its syntax, and how you can use it to find out where apt-get installs packages.

The general syntax of this command is as follows.

$ dpkg [actions]

Another common method of using it is:

$ dpkg [options] filename

You can install a package on your Linux system by running the following simple dpkg command.

$ dpkg -i packagename

We will understand how one can use dpkg and apt-get to install packages and learn where the packages are installed in the following sections.

How does apt-get work?

By this point, we all know that apt-get can be used to install, remove, and upgrade Linux packages. We also learned that it serves as the front-end for dpkg, the native package management utility for Ubuntu and Debian. But how does it really work? And what happens to the files that are installed by it? Let’s find out!

Let us start by installing a test package called ack. For this purpose, we will use apt-get, and later we will trace the files installed by it to their specific locations.

Go ahead and start a new Terminal window through the Activities menu or pressing Ctrl + Alt + T on your keyboard. The next step is to make sure you have the multiverse repository added. Without that, you cannot install ack. You are, obviously, free to use any other package of your choice.

So, to add the repository, run the following command in the Terminal.

$ sudo apt-add-repository multiverse

Once that is out of the way, we move on to installing the package.

$ sudo apt-get install ack

(Note that instead of ack-grep, ack was installed. This is why we will be modifying the next commands we execute)

The installation will be complete within a few seconds. Having done that, we now investigate the package with the help of our package manager, dpkg. We will find out where the files of the package were installed and how to access them.

Recall the general syntax of the dpkg command that we described in the earlier sections. Here, we will be using a variation of that command to list the files in the installed package.

To list the contents of a package, we use the -L operator with the dpkg command. Run the command given below to see the files.

$ dpkg -L ack

As you can see in the image, all the package manager installed files are shown along with their addresses on the computer.

In addition to that, some files are created or modified by pre/postrm and pre/postinstall scripts included in the installed package. You can view these scripts in the following directory.

/var/lib/dpkg/info

Additional Information

Now that we have covered the meat of the tutorial, we will add some additional pieces of information for those that are curious about learning more.

Let’s say, for example, you want to use dpkg to extract all the files of a package in the current directory. You can do this by running the following simple command.

$ dpkg -x packagename

You can also get a hold of the files such as preinst, postrm, postinst, and more by the command given below.

$ dpkg -e packagename

This will extract said files into the current directory as well.

Conclusion

With that being said, we conclude this guide. We learned several things about apt-get today. We saw the Filesystem Hierarchy Standard, how the Ubuntu package manager works, and finally, how we can find where apt-get installs packages to.

About the author

Zeeman Memon

Hi there! I'm a Software Engineer by degree, Blogger by skills who loves to write about tech, develop websites & do SEO. You can reach out to me on LinkedIn.