Chapter 32. APT

Objectives

  • Explain what APT is
  • Use apt-cache to perform queries
  • Install, remove and upgrade packages using apt-get

What APT is ?

Stands from Advance Package Tool, which includes a number of utilities such as apt-get and apt-cache. These of course in turn invoke the lower level dpkg program.

Apt-get

Is the main APT command line tool for package management. It can be used to install, manage and upgrade individual packages or the entire system. It works with multiple repositories

Queries Using apt-cache

Search the repository for a package name apache2

$ sudo apt-get search apache2

Display basic information about the apache2 package

$ apt-cache show apache2

Display more detailed information about the apache2 package

$ apt-cache showpkg apache2

List all dependent packages for apache2

$ apt-cache depends apache2

Search the repository for a file name apache2.conf

$ apt-file search apache2.conf

List all files in the apache2 package

​$ apt-file list apache2

Installing Removing Upgrading

The apt-get program is the work horse of installing, removing and upgrading packages

Synchronize the package index files with their repository sources. The indexes of available packages are fetched from the location specified in 

​/etc/apt/sources.list

Install new packages or update an already installed package

$ sudo apt-get install [package]

Remove a package from the system without removing its configuration files

$ sudo apt-get remove [package]

​Remove a package from the system and its configuration files as well

$ sudo apt-get --purge remove [package]

​Apply all available updates to packages already installed

​$ sudo apt-get upgrade

Do a smart upgrade that will do a more thorough dependency resolution and remove some obsolete packages and install new dependencies

​$ sudo apt-get dist-upgrade

This will not update to a whole new version of the Linux distribution as is commonly misunderstood.
Note that you must update before upgrade, unlike yum where the update argument does both steps, it updates the repositories and then upgrades the packages.

Get rid of any packages not needed anymore, such as older Linux kernel versions

$ sudo apt-get autoremove

Clean out cache files and any archived packages files that have been installed

$ sudo apt-get clean

​Laboratories