The apt command in Linux: package manager in Debian and Ubuntu

Introduction

The apt package manager is one of the most used tools in Debian-based distributions, such as Ubuntu and Linux Mint. Its design allows installing, updating, and removing software easily from the command line, leveraging official and third‑party repositories.

What is apt and how does it work?

Apt (Advanced Package Tool) is a frontend for dpkg that manages the download, dependency resolution, and installation of .deb packages. It works with source list files located in /etc/apt/sources.list and in the directory /etc/apt/sources.list.d/.

Updating the package list

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

sudo apt update

The command downloads the Packages.gz files and compares the available versions, without installing anything.

Upgrading the system

With the index updated you can apply all available upgrades:

sudo apt upgrade

This command updates installed packages to their latest versions while keeping dependencies. To perform a full upgrade that may change dependency versions by removing obsolete packages, use:

sudo apt full-upgrade

Installing packages

To install a new package use:

sudo apt install package_name

If you wish to install a specific version you can specify:

sudo apt install package_name=1.2.3-4ubuntu1

Moreover, apt allows installing several packages at once by separating them with spaces.

Removing packages

To remove a package while leaving its configuration files:

sudo apt remove package_name

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

sudo apt purge package_name

Searching for packages

Before installing it is useful to search the repositories:

apt search keyword

To get detailed information about a package:

apt show package_name

Cleaning 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 are no longer needed:

sudo apt autoremove

Advanced options and tips

  • --no-install-recommends: avoids installing recommended packages that are not strictly required.
  • --reinstall: forces reinstallation of a package, useful when suspecting corrupted files.
  • -s or --simulate: shows what would happen without making real changes.
  • Use apt list --upgradable to see which packages have pending upgrades.
  • Configure /etc/apt/apt.conf.d/20auto-upgrades to enable automatic updates on servers.

Conclusion

Mastering apt allows efficient software management on any Debian‑based system. With the basic commands and a few advanced options you can keep the system up‑to‑date, secure, and free of unnecessary packages.

This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .