APT (Advanced Packaging Tool) is a utility for installing, updating and uninstalling software packages on Debian and Debian-based operating systems (Ubuntu, Linux Mint, etc.). It can automatically install and configure programs for UNIX-like operating systems both from precompiled packages and from source code.

Packages are taken from Internet repositories, or you can install them from available media. The list of package sources is stored in /etc/apt/sources.list and in /etc/apt/sources.list.d/. The graphical shells for apt make it easy to add new sources and remove unwanted ones.

The direct manipulation of packages is done with apt-get, the basic commands for manipulating which will be described below.

The general structure of the apt-get command*

apt-get [options] command package1 package2 ... packageN  

Options may be useful when working with apt-get:

  • -h - Help call.

  • -d - Load packages without installing and unpacking. The downloaded packages will be located in /var/cache/apt/archives.

  • -s - Simulates command execution.

  • -y - With this option all questions will be automatically answered with Yes. At the same time the questions themselves will not be displayed.

  • -f - Ignore the result of packet integrity check.

  • -u - Display the list of updated packages.

*-u - Update the list of packages available for installation

This action is performed using the command:

apt-get update  

Updating the list is important if you want to install the most recent and stable version of a package. When you run this command, the program looks through the archives specified in the /etc/apt/sources.list file.

Installing the package

In order to install any package, the command is used:

apt-get install packagename  

As a result, APT will look for a fresh version of the specified package and check if it has any dependencies. If there are dependencies, it will list them and offer to install.

# apt-get install aee
Reading state information... Done  
The following extra packages will be installed:  
  libx11-6 libx11-data libxau6 libxcb1 libxdmcp6
The following NEW packages will be installed:  
  aee libx11-6 libx11-data libxau6 libxcb1 libxdmcp6
0 upgraded, 6 newly installed, 0 to remove and 44 not upgraded.  
Need to get 181 kB/1297 kB of archives.  
After this operation, 4366 kB of additional disk space will be used.  
Do you want to continue [Y/n]?  

If there are no dependencies, the installation process will happen automatically and no questions asked.

It is also possible to specify the names of packages to be removed when entering the command to install packages. To do this, add a hyphen at the end of the name of the package to be removed

Installation/removal example:

# apt-get install aee htop-
Reading state information... Done  
The following extra packages will be installed:  
  libx11-6 libx11-data libxau6 libxcb1 libxdmcp6
The following packages will be REMOVED:  
  htop
The following NEW packages will be installed:  
  aee libx11-6 libx11-data libxau6 libxcb1 libxdmcp6
0 upgraded, 6 newly installed, 1 to remove and 43 not upgraded.  
Need to get 1297 kB of archives.  
After this operation, 4157 kB of additional disk space will be used.  
Do you want to continue [Y/n]?  

As you can see from the example, package aee is prepared for installation and package htop is prepared for removal.

Reinstalling the package*

If you need to reinstall a package (file corruption, newer version), you can do so with the following command:

apt-get --reinstall install packagename  

Remove package

There are two options to remove packages:

  • Deleting a package except for the configuration files (if any).

This option may be necessary if you plan to reinstall this package in the future

apt-get remove packageagename  

It is also worth noting that if the package to be removed has dependencies, it will be removed along with them.

  • Full removal of a package

Unlike the first method, it will remove all files that are related to the removed package, including configuration files.

apt-get --purge remove packageagename  

Packages that are marked for complete removal have the symbol "*" at the end of their name

  • Uninstall and install in one command

You can also mark a list of packages for installation when uninstalling. To do this you need to put "+" at the end of the package name.

# apt-get --purge remove aee screen+
Reading state information... Done  
The following packages will be REMOVED:  
  aee*
The following NEW packages will be installed:  
  screen
0 upgraded, 1 newly installed, 1 to remove and 43 not upgraded.  
Need to get 624 kB of archives.  
After this operation, 975 kB of additional disk space will be used.  
Do you want to continue [Y/n]?  

Package refresh

We recommend that you refresh the list of available packages before running an upgrade with

apt-get update  

This will update the information about the available packages and their versions. After executing this command, you can proceed directly to update the installed packages on your system. This is done with the command:

apt-get -u upgrade  

The specified parameter -u is used to get a complete list of packages which will be prepared for the upgrade.

*-u upgrade distribution version

If there is a new version of the OS distribution you have installed, you can "upgrade" the whole system with the command:

apt-get -u dist-upgrade  
Updated Feb. 25, 2019