Apt-get and apt command on Linux (install packages)
The apt-get (Advanced Package Tool) command is an advanced package manager for Linux from the Debian family, such as Debian itself, Ubuntu, Kali and Mint.
It can use local or remote files to install or update packages. This way it is possible to update the entire Debian system via ftp or http. This manager also maintains information about packages and their dependencies.
Because of its ease of operation, apt-get is the preferred To Install method for manipulating packages. This utility offers dozens of options configured in the /etc/apt/apt.conf file.
The /etc/apt/sources.list file contains the locations where apt-get will find the packages, the verified distribution (stable, testing, unstable, Woody, Sarge) and the section that will be copied (main, non-free, contrib, non-US).
Below is a simple example of the /etc/apt/sources.list file with an explanation of the sections:
In the /etc/apt/apt.conf file we can specify options that will modify the behavior of the apt-get program when manipulating packages.
apt-get uses a list of packages to check whether existing packages on the system need to be updated or not. The newest list of packages is copied using the apt-get update command.
Apt-get is very useful because the administrator does not have to manually copy the package he wishes to install from the Internet, much less deal with the dependencies, as long as what he needs is in the repositories indicated on sources.list.
The most common options for this utility are:
- -d: Download the files but don’t install. It is useful for downloading large volumes of packages for subsequent installation;
- -s: Simulates the installation of the packages but does not make modifications;
- -y: Answers in the affirmative for all questions asked during the installation/uninstallation process of the packages.
The most common commands are:
- dist-update: This command automatically updates the Debian system;
- install: This command installs a specific package specified by name;
- remove: This command removes a particular package specified by name;
- update : This command makes a list of all available packages. The process is done automatically before any modifications to the packages;
- upgrade: This command is used to safely update the system, since it does not install packages that may cause any conflict or failure in the configuration files.
Examples:
Install the airsnort.x.y.deb package. This command accepts installing more than one package by separating names by spaces. You only need to specify the package name, without version (X), revision (Y), and suffix (.deb).
If necessary, apt-get will automatically install the dependencies necessary for the correct functioning of a package.
Apt-get is also widely used to update all system packages, with the update command to update the databases with the new packages and then the upgrade command to make the updates:
apt-get can update your entire distribution in a smart and secure way. It reads the list of packages available on the remote server, checks which are installed and their versions, and updates the old packages.
But what about the apt command? How is it different?
Since 2014, distributions based on Debian have included an improvement to apt-get, which combined and improved several tools that made up the apt-get package. This new vitamin version of apt-get became known only as apt.
Apt does everything that apt-get does. So, to install, update, and remove packages on a daily basis, it doesn’t matter if you use apt or apt-get.
To install one or more packages with apt:
To remove one or more packages:
From time to time, one or more files that make up an installed package may be damaged or removed by accident. Thus, the easiest way to recover these files is to reinstall the affected package.
Unfortunately, the packaging system may notice that the package is already installed and will refuse to reinstall it. To circumvent the system and force a reinstallation of a package, apt’s —reinstall option should be used.
In the example the httpd package is reinstalled:
To update the installed packages with the latest version available in the repository, use the update and then upgrade commands.
The update downloads the updated package list.
To effectively upgrade:
The apt package manager keeps a copy of each downloaded .deb file in the /var/cache/apt/archives/ directory.
Over time, this directory can take up a lot of disk space. To clear the apt cache, use the clean command:
To switch from one major version of Debian or Ubuntu to the next, you need to use the apt full-upgrade command. With this instruction, apt will complete the update, removing some obsolete packages and installing new dependencies:
Always make a backup before updating the system using a full-upgrade. If you want to see how to update your Ubuntu, read this post.
Conclusion
If you use Debian or Ubuntu, it is essential to learn the apt command to manage packages on these systems.