Question: What does the `apt-get install ...` command do?

When I enter `apt-get install ...` command, there are some texts appearing on the screen, but that does not have enough information for me. I want to know if any file is created / edited, any service is started and other activities...

Is there any `.sh` file executed when the `apt-get install ...` run? If so, how can I see the content of that `sh` file?

The reason for this question is recently I tried to install tomcat7 with `apt-get install tomcat7`. Everything works fine until I install `tomcat7-admin` (manager web application), the server became unresponsive to any request. I tried this many times, and this always happen.

Answer: 
**In short**: `apt-get install` does everything that is needed that your system can successfully execute the new installed software application.

**Longer:** 

**Preliminaries:**

From the [manpage](http://manpages.ubuntu.com/manpages/trusty/en/man8/apt-get.8.html): 

> 
> All packages required by the package(s) specified for installation
>  will also be retrieved and installed.
> 
> 
> 

Those packages are stored on a repository in the network. So, `apt-get` downloads all the needed ones into a temporary directory (`/var/cache/apt/archives/`). They will be downloaded from a web- or a ftp-server. They are specified in the so called `sources.list`; a list of repositories. From then on they get installed one by one procedurally.

The first ones are the ones, that have no further dependencies; so no other package has to be installed for them. Through that, other packages (that had dependencies previously) have now no dependencies anymore. The system keeps doing that process over and over until the specified packages are installed.

Each package undergoes an installation procedure.

**Package installation:**

In Debian-based Linux distributions, as Ubuntu, those packages are in a specified standardized format called: deb - [The Debian binary package format](http://en.wikipedia.org/wiki/Deb_%28file_format%29).

Such a package contains the files to be installed on the system. Also they contain a [control file](https://www.debian.org/doc/debian-policy/ch-controlfields.html). That file contains scripts that the packaging system should execute in a specific situation; the so called [maintainer scripts](https://wiki.debian.org/MaintainerScripts). Those scripts are split in:

* `preinst`: before the installation of the files into the systems filehierarchy
* `postinst`: after the installation
* `prerm`: before the uninstallation
* `postrm`: after the uninstallation

There is an interesting picture, showing the procedure of an installation of a new package:

![installation](https://i.stack.imgur.com/yp41b.png)

There are also more control-files, the most important are as follows:

* `control`: A [list](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles) of the dependencies, and other useful information to identify the package
* `conffiles`: A [list](https://www.debian.org/doc/manuals/maint-guide/dother.en.html#conffiles) of config files (usually those in `/etc`)
* `debian-binary`: contains the deb-package version, [currently 2.0](http://tldp.org/HOWTO/Debian-Binary-Package-Building-HOWTO/x60.html#AEN66)
* `md5sums`: A list of md5sums of each file in the package for verifying
* `templates`: A file with [error descriptions and dialogs](https://www.debian.org/doc/packaging-manuals/debconf_specification.html#AEN45) during installation
For the actual *under-the-hood* stuff, you'll need to grab the Apt source. Fairly simple if you have source repositories enabled:

```
apt-get source apt

```

The `apt-get` command itself lives in `cmdline/apt-get.cc`. It's a pain to read through but most of `apt-get`'s actions are spelled out quite extensively in there. Installation however, is mapped through a `DoInstall` function which lives in `apt-private/private-install.{cc,h}`.

You have to remember that apt-get is merely one side of the coin.  

`dpkg` is handling the actual installation but `DoInstall` doesn't know about `dpkg` directly. `apt-get` is actually surprisingly package-manager agnostic. All the functionality is abstracted through `apt-pkg/package-manager.cc`

I'm only looking briefly but even there I can't see where this actually attaches to the `dpkg` systems. Some of this seems to be autoconfigured through `apt-pkg/aptconfiguration.cc` but this is a deep well. You could spend days unravelling this.

The source documentation is good though. You could do worse things than to go through each file and read the header to work out what's actually happening.