apt-get is a command from the APT suite of tools that is used to install, upgrade or remove software packages in Debian and Debian-based Linux distributions. This command has some neat features, such as ease of use over simple terminal connections (SSH) and the ability to be used in system administration scripts, which can in turn be automated by the cron scheduling utility.
The apt-get command obtains information about available packages from the sources listed in /etc/apt/sources.list and then uses that information to upgrade or install packages. Here is an example sources.list file:
Note the lines that begin with deb and deb-src. These are the sources from which packages can be obtained; deb indicates binary packages (the pre-compiled packages that we normally use), and deb-src indicates source packages.
Update the list of available packages
To obtain updated information about packages available from the installation sources listed in /etc/apt/sources.list, use the apt-get update command:
Upgrade all installed packages to the newest versions
To upgrade all installed packages, use the apt-get upgrade command. You can use the -u option to display the complete list of packages which will be upgraded:
Perform the upgrade of all installed packages and handle the changing dependencies
To perform the upgrade but also to perform smart conflict resolution to avoid upgrading a package if doing so would break a dependency, use the apt-get dist-upgrade command:
Install a package by package name
To install a package by its name, use the apt-get install PACKAGE_NAME command:
apt-get searches the database for the most recent version of nmap and retrieves it from the corresponding archive as specified in sources.list. In the event that nmap depends on other packages – as is the case here – apt-get checks the dependencies and installs the needed packages.
Remove a package by package name
To remove a package by its name, use the apt-get remove PACKAGE_NAME command:
Check the package database for consistency
To check the package database for consistency and broken package installations, use the apt-get check command.
Remove unused package files
To clear out information about retrieved files from the Debian package database, use the apt-get clean command. This command removes everything but the lock file from /var/cache/apt/archives and /var/cache/apt/archives/partial:
The apt-get command actions, such as installation and removal of packages, are logged in the /var/log/dpkg.log file: