apt-get command

The apt-get command is a command-line tool used to work with Ubuntu's Advanced Packaging Tool (APT) performing such functions as installation and upgrade of software packages, updating of the package list index, and even upgrading the entire Ubuntu system.
Being a simple command-line tool, apt-get has some advantages over other package management tools available in Ubuntu for server administrators. Some of these advantages include 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 scheduler.
Note that the sudo command is used to perform the following tasks as the root user.
Examples of the apt-get utility
Install a Package: For example, to install the network scanner nmap, type the following:
sudo apt-get install nmap
To (completely) remove a Package:
sudo apt-get --purge remove packagename
Multiple Packages: These can be installed or removed, separated by spaces.
Update the Package Index: The APT package index is essentially a database of available packages from the repositories defined in the /etc/apt/sources.list file. To update the local package index with the latest changes made in repositories, type the following:
sudo apt-get update
Upgrade Packages: Over time, updated versions of currently installed packages become available from the package repositories (for example security updates). To upgrade a system, first update the package index as outlined above, and then type:
sudo apt-get upgrade
If a package needs to install or remove new dependencies when being upgraded, it will not be upgraded by the upgrade command. For such an upgrade, it is necessary to use the dist-upgrade command.
The entire Ubuntu system can be upgraded from one revision to another with dist-upgrade. For example, to upgrade from Ubuntu version 5.10 to version 6.06.1 LTS, first ensure the version 6.06.1 LTS repositories replace the existing 5.10 repositories in the system's /etc/apt/sources.list, then issue the apt-get update command as detailed above. Finally perform the actual upgrade by typing:
sudo apt-get dist-upgrade
A revision upgrade can take some time. Typically, some post-upgrade steps would be required as detailed in the upgrade notes for the revision you are upgrading to.
Actions of the apt-get command, such as installation and removal of packages, are logged in the /var/log/dpkg.log file.
For further information about the use of APT, see the Debian APT User Manual or type:
apt-get help
This document is based on the Ubuntu help page located at: https://help.ubuntu.com/6.06/ubuntu/serverguide/C/apt-get.html