apt-get install does everything that is needed that your system can successfully execute the new installed software application.
From the manpage:
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 (internet). So,
apt-get downloads all the needed packages 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 for the package manager apt. From then on, they get installed one by one procedurally.
The first ones to be installed are the ones, that have no further dependencies; so no other package has to be installed for them to work properly. Trough that, other packages (that had dependencies previously) haven't now 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 procedure:
In Debian-based Linux distributions, as Ubuntu or Mint, those packages are in a specified standardized format called: deb --> The Debian binary package format.
Such a package contains the files to be installed on the system. Also they contain a control file. That file contains scripts that the packaging system should execute in a specific situation; the so called maintainer scripts. Those scripts are splitted in:
preinst: before the installation of the files into the systems file hierarchy
postinst: after the installation
prerm: before the uninstallation
postrm: after the uninstallation
Those scripts are the place where specific users are created or some services that need to be restarted or other preliminaries that are needed for the package to work.
Besides those scripts the package system has triggers that are intended for specific events. For example the regeneration of initrds when installing a new kernel version or ldconfig or the man-db. They are activated by one or more packages and run in the end of the whole installation process.
There is an interessting picture, showing the procedure of an installation of a new package:
There are also more control-files, the most important are as follows:
If you are interessted you can unpack a deb package (after downloading) manually and watch whats inside:
# to only download the package (no installation)
apt-get download package
# to unpack the deb file
ar x package.deb
Now you see a file called
data.tar.gz containing the files and a file called
control.tar.gz containing the four maintainer scripts and the above mentioned control-files.