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
There are some fantastic answers here which are better than this short one, but something you might consider to help you get a better understanding of the changes made by a package manager is [Docker](https://www.docker.com). You can diff the changes made in a container using `docker diff <container>` and it will show you all of the changes. This is especially useful for taking a look under the hood to see what `apt-get install` does to a system. A quick search will get you [several](http://www.scriptrock.com/blog/comparing-containers-generating-dockerfiles-guardrail) [resources](https://stackoverflow.com/questions/21200304/docker-how-to-show-the-diffs-between-2-images) to help implement this.