Categories: Package Management

Apt-get and apt command on Linux (install packages) [Basic Guide]

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:

deb http://www.debian.org/debian stable main contrib non-free
deb http://nonus.debian.org/debian-non-US stable non-US

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:

# apt-get install airsnort

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 update
# apt-get upgrade

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.

# apt-get dist-update

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:

# apt install package1 package2

To remove one or more packages:

# apt remove package1 package2

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:

# apt --reinstall install httpd

To update the installed packages with the latest version available in the repository, use the update and then upgrade commands.

# apt update

The update downloads the updated package list.

To effectively upgrade:

# apt 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:

# apt clean

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:

# apt full-upgrade

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.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.