The Linux apt command: Debian and Ubuntu package manager

Introduction

The package manageraptis one of the most used tools in Debian-based distributions, such as Ubuntu and Linux Mint. Its design allows you to install, update and remove software easily from the command line, taking advantage of official and third-party repositories.

What is apt and how does it work?

Apt (Advanced Package Tool) is a front ofdpkgwhich manages the download, unit resolution and installation of .de. packages. Works with source list files located in/etc/apt/sources.listand in the directory/etc/apt/sources.list.d/.

Update the package list

Before any operation it is recommended to synchronize the local index with the remote repositories. This is achieved by:

sudo apt update

The command download the filesPackages.gzand compare the available versions, without installing anything.

Update the system

With the updated index you can apply all available updates:

sudo apt upgrade

This command updates the installed packages to their latest versions, maintaining the dependencies. To make a complete update that can change versions of units by removing obsolete packages:

sudo apt full-upgrade

Install packages

To install a new package:

sudo apt install nombre_del_paquete

If you want to install a specific version you can indicate:

sudo apt install nombre_del_paquete=1.2.3-4ubuntu1

In addition, apt allows you to install several packages at the same time by separating them by spaces.

Remove Packages

To remove a package by leaving the configuration files:

sudo apt remove nombre_del_paquete

If you want to delete also the configuration files you use:

sudo apt purge nombre_del_paquete

Search packages

Before installing it is useful to search the repositories:

apt search palabra_clave

For detailed information on a package:

apt show nombre_del_paquete

Clean cache and unnecessary packages

Over time, the download cache takes up space. It can be cleaned with:

sudo apt clean

To automatically remove packages that were installed as dependencies and no longer necessary:

sudo apt autoremove

Advanced Options and Tips

  • --no-install-recommends: avoids installing recommended packages that are not strictly necessary.
  • --reinstall: forces the reinstallation of a package, useful when suspected of corrupt files.
  • -sor--simulate: shows what would happen without making real changes.
  • Useapt list --upgradableto see which packages have updates pending.
  • Configure/etc/apt/apt.conf.d/20auto-upgradesto activate automatic updates on servers.

Conclusion

Domainaptallows efficient management of the software on any Debian-based system. With basic commands and some advanced options you can keep the system up to date, safe and free of unnecessary packages.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish