SafeITExperts

SafeITExperts

Your expert guide to cybersecurity and digital privacy. Security hardening for all platforms : Windows, macOS, Linux, and Android. Solutions aligned standards : NIST and ANSSI for comprehensive digital protection.


Debian APT Tutorial 2026: apt, apt-get, aptitude

Publié par Marc sur 27 Février 2026, 06:57am

Catégories : #APT, #Debian, #administration systèm

Debian APT Tutorial 2026: apt, apt-get, aptitude | SafeITExperts
Search
Menu

Debian APT Tutorial 2026: apt, apt-get, aptitude

🚀 From Beginner to Expert — Everything you need to know about Debian package management
2026Updated: 02/24/2026 Read: 50 min2 Parts
📦 APT🐧 Debian📥 dpkg🔄 Sid🛡️ Stable⚙️ aptitude
1
Global Overview of APT

📖 Preamble

In the Debian ecosystem — Stable, Testing or Sid — APT (Advanced Package Tool) is the central software management tool. It relies on dpkg for individual package manipulation and provides a powerful interface to install, update and remove software, while automatically managing dependencies.

APT Debian Package Management
Guide Basis

This guide uses Debian 13 "trixie" as the Stable base, with Testing (forky) and Sid (unstable) as development branches. All commands and examples are verified for trixie.

Goal

Master APT progressively, from beginner to expert, with concrete practical use cases and verified commands.

👥 Target Audience

🌱
Beginner
Get up and running quickly
Sections: Starter Pack
🌿
Intermediate
Comprendre dépôts, priorités, updates
Sections : Concepts & Pratiques
🌳
Expert
Dépannage, migrations, commandes sensibles
Sections : Avancé & Critiques

📚 How to Read This Guide

LevelContentRecommendation
🟢 EssentialCommon commands, examplesMaster first
🟠 IntermediateConcepts, workflowsFor deeper understanding
🔴 ExpertCritical cases, advanced operationsFor experienced users only

❓ What is APT?

ElementDescription
RolePackage manager for Debian and its derivatives
EngineBased on dpkg
StrengthsAutomatic dependency resolution, fine-grained repository management, stability, community
AudienceAll Debian users, from beginners to administrators

📝 Basic Syntax

General Structure

APT Syntax
apt [OPTIONS] COMMANDE [ARGUMENTS]
apt-get [OPTIONS] COMMANDE [ARGUMENTS]
apt-cache [OPTIONS] COMMANDE [ARGUMENTS]
aptitude [OPTIONS] COMMANDE [ARGUMENTS]

Breakdown

ElementRoleExample
OPTIONSOptions applied to the command-y, --simulate, -V
COMMANDThe main action to performinstall, remove, update, upgrade
ARGUMENTSWhat the action applies toPackage name, version, .deb file

Annotated Example

Example
# Install htop without recommendations, auto yes mode
$sudo apt -y install --no-install-recommends htop
# -y = global option (auto yes)
# install = command
# --no-install-recommends = command option
# htop = argument

🧩 Distinction entre apt, apt-get, apt-cache et aptitude

ToolMain RoleInterfaceAudience
aptCommon user commandsConcise, colorfulDaily use
apt-getLegacy package managementBare, scriptsAutomation
apt-cacheCache queryingCommand linesAdvanced searches
aptitudeInteractive text interface + CLICursor/line modeComplex conflict resolution

Recommendation: apt for interactive use, apt-get for scripts, apt-cache for precise queries, aptitude as a last resort.

🏗️ Internal Architecture: APT + dpkg

┌────────────┐     ┌──────────────────┐     ┌──────────────────┐
│    APT     │ ──▶ │       dpkg       │ ──▶ │  Linux System    │
└────────────┘     └──────────────────┘     └──────────────────┘
       │                    │                        │
       ▼                    ▼                        ▼
CLI Interface       Installation/Removal        File Management
Repository Mgmt     Package database            Maintainer scripts
Dependency            of installed packages
resolution

Component Roles

ComponentRoleImportance
APTUser interface, repository management, dependency resolutionDaily interaction
dpkgActual installation, local databaseSystem core
PinningRepository priority controlStability / customization

📦 Repositories

Repository Role: The Foundation of Everything

Repositories are defined in /etc/apt/sources.list and /etc/apt/sources.list.d/.

┌─────────────────────┐
│  Debian 13 trixie   │  (main, contrib, non-free, non-free-firmware)
└─────────────────────┘
           │
┌─────────────────────┐
│  Debian Security    │  (security updates)
└─────────────────────┘
           │
┌─────────────────────┐
│  trixie-updates     │  (stable updates)
└─────────────────────┘
           │
┌─────────────────────┐
│  trixie-backports   │  (more recent versions, targeted use)
└─────────────────────┘

Repository Types

TypeContentNotes
mainOfficial free packagesSupported by Debian
contribFree packages depending on non-free ones
non-freeNon-free packagesProprietary drivers
non-free-firmwareProprietary firmware (WiFi, GPU, microcode)Required for much modern hardware — Debian 13+
securitySecurity patchesEssential for Stable
backportsRecent versions for StableOfficial, targeted use (not for the whole system)
experimentalVery fresh, unstable packagesFor testing only

Repository Lifecycle

Ajouter manuellement
 │
 ▼
Modifier (éditer le fichier)
 │
 ▼
Activer / Désactiver (commenter)
 │
 ▼
Supprimer (effacer la ligne)

DEB822 Format — Recommended for Debian 13

New Recommended Format

Debian 13 trixie favors files in /etc/apt/sources.list.d/*.sources in DEB822 format to declare repositories. The sources.list format remains supported for compatibility.

DEB822 Example — /etc/apt/sources.list.d/debian.sources
Types: deb
URIs: http://deb.debian.org/debian
Suites: trixie trixie-updates
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
Types: deb
URIs: http://security.debian.org/debian-security
Suites: trixie-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

Best Practices by Use Case

DistributionRecommended RepositoriesDiscouraged Repositories
Stable (trixie)main, contrib, non-free, non-free-firmware, security, trixie-updatesexperimental — backports: official but targeted use only
Testing (forky)main, contrib, non-free, non-free-firmwareexperimental (may desynchronize)
Sidmain, contrib, non-free, non-free-firmwarebackports (useless on Sid)
Serversmain, non-free-firmware, security, trixie-updatescontrib, non-free if possible

⚖️ Repository Priorities (Pinning)

The APT priority system lets you control which repository takes precedence.

APT doit installer un paquet :
        │
        ▼
  1. Dépôt avec la priorité la plus élevée
        │
        ▼
  2. Version la plus récente (si priorités égales)
        │
        ▼
  3. Dependency resolution
Priority Meanings (Debian source)
  • P < 0: never installed
  • 1-99: only if no other version is installed
  • 100: default priority for already installed version
  • 101-499: only if no higher priority source exists
  • 500: standard priority of the target distribution
  • 501-989: only if no newer version in the target
  • 990-1000: unless installed version is more recent
  • >1000: always installed, even if forced downgrade

🔄 Stable vs Testing vs Sid — In 20 Seconds

🛡️
Stable — trixie
Debian 13, robust distribution

Type: Stable, frozen

Risks: Low

Use: Servers, production, desktop

Routine: apt upgrade

Transition: apt full-upgrade

🚀
Testing — forky
Future Debian, pre-release

Type: Frozen rolling

Risks: Moderate

Use: Desktop, testers

Command: apt full-upgrade

💥
Sid (Unstable)
Permanent rolling

Type: Rolling

Risks: High

Use: Developers, experts

Command: apt full-upgrade

2
APT Commands

🚀 Starter Pack — The 15 Essential Commands

1
sudo apt update
Refresh the package list
2
sudo apt upgrade
Standard update (Stable)
3
sudo apt full-upgrade
Full upgrade (Testing/Sid)
4
sudo apt install <pkg>
Install a package
5
sudo apt remove <pkg>
Remove (keeps config)
6
sudo apt purge <pkg>
Remove completely
7
apt search <pattern>
Search for a package (modern, colorful) — apt-cache search <pattern> for scripts
8
apt show <pkg>
Detailed information
9
apt list --installed
List installed packages
10
apt-file search <file>
Which package provides this file?
11
sudo apt autoremove
Remove unnecessary dependencies
12
sudo apt clean
Clean the cache
13
sudo apt autoclean
Clean obsolete packages
14
apt-mark showhold
Show locked packages
15
sudo apt --fix-broken install
Fix broken dependencies

📦 Repository Management

Inspect Repositories

Inspect
$apt-cache policy
$cat /etc/apt/sources.list
$ls /etc/apt/sources.list.d/

Add, Remove, Modify

Management
# Add a repository (manual)
$echo "deb http://deb.debian.org/debian trixie-backports main" | sudo tee /etc/apt/sources.list.d/backports.list
# Modify
$sudo apt edit-sources
# Remove
$sudo rm /etc/apt/sources.list.d/backports.list

🔍 Advanced apt-cache Commands

CommandDescription
apt-cache policy [package]Priorities and available versions
apt-cache showpkg <package>Internal info (reverse dependencies)
apt-cache depends <package>Lists dependencies
apt-cache rdepends <package>Lists packages that depend on it
apt-cache statsCache statistics
apt-cache unmet ⚠️Unmet dependencies (deprecated on Debian 13 — prefer apt check)
apt-cache madison <package>Available versions with origin

📥 Installation / Update / Removal

apt upgrade vs apt full-upgrade vs apt-get dist-upgrade

Criterionupgradefull-upgrade / dist-upgrade
Updates packages✔️ Yes✔️ Yes
Installs new packages❌ No✔️ Yes (if needed)
Removes packages❌ No✔️ Yes (if needed)
Recommended useStableTesting, Sid, migration

Advanced Installation

Installation
# Install multiple packages
$sudo apt install git curl vim
# Specific version
$sudo apt install vim=2:9.0.1378-2
# From a specific distribution (e.g.: unstable)
$sudo apt install -t unstable apache2
$sudo apt install apache2/unstable
# Reinstall
$sudo apt install --reinstall bash
# Simulate
$sudo apt install --simulate htop
# Install a local .deb file (with dependency resolution)
$sudo apt install ./package.deb

Removal

Removal
$sudo apt remove htop
$sudo apt purge htop
$sudo apt remove --auto-remove htop
# Remove and install in one line (+/- syntax)
$sudo apt install package1 package2-
$sudo apt remove package1+ package2

Locks

Locks
$sudo apt-mark hold linux-image-amd64
$apt-mark showhold
$sudo apt-mark unhold linux-image-amd64

Cleanup

Cleanup
$sudo apt clean
$sudo apt autoclean
$sudo apt autoremove --purge
$sudo aptitude purge ~c

🛠️ Maintenance & Diagnostic

Broken Packages

Diagnostics
$sudo apt --fix-broken install
$sudo apt check
$sudo dpkg --configure -a
$dpkg -l | grep ^[a-z][a-z]

Blocking Processes

Processes
$sudo lsof | grep ' (deleted)'
$sudo needrestart

Dependencies and Consistency

Dependencies
$apt-cache depends <package>
$apt-cache rdepends <package>
$sudo debsums -c

⚡ Advanced Commands (Expert)

Working with Multiple Distributions

Multi-distrib
# Lock trixie as the default distribution (base of this guide)
echo 'APT::Default-Release "trixie";' | sudo tee /etc/apt/apt.conf.d/99default
# Install a package from Sid while keeping trixie as the base
$sudo apt install -t unstable package-name

Fine-grained Pinning

Pinning
# /etc/apt/preferences.d/pin-backports
Package: *
Pin: release a=trixie-backports
Pin-Priority: 100

Complementary Tools

ToolDescriptionExample Command
apt-listbugsShows bugs before installationapt-listbugs list apache2
apt-listchangesShows recent changesapt-listchanges --apt
apt-rdependsRecursive dependenciesapt-rdepends vlc
aptitude whyWhy an auto package is installedaptitude why python3
nalaModern optional frontend for APTapt install nala then nala --help

🔧 Tools Requiring Installation

Some advanced commands and tools mentioned in this guide are not installed by default on Debian. To use them, simply install the corresponding packages.

ToolRoleInstallation
apt-fileFind the package providing a filesudo apt install apt-file
deborphanList orphaned packagessudo apt install deborphan
needrestartCheck which services need restarting after updatesudo apt install needrestart
apt-listbugsDisplay bugs before installationsudo apt install apt-listbugs
apt-listchangesView recent package changessudo apt install apt-listchanges
aptitudeInteractive package management interfacesudo apt install aptitude
nalaModern APT frontend (improved display)sudo apt install nala

⚠️ Dangerous Commands — Red Zone

Warning

Some commands can break a system if used incorrectly.

CommandDanger
dpkg --force-depends -i package.debIgnores dependencies
apt-get -o Dpkg::Options::="--force-confnew" dist-upgradeOverwrites modified config files
dpkg --purge --force-all <package>Removes even with dependencies

Best Practices

  • Always simulate with --simulate
  • Back up configurations
  • Use apt-mark hold on critical packages

🏆 Top 12 Advanced APT Commands

1
sudo apt install -t <release> <pkg>
Install from a specific distribution
2
sudo apt-get --simulate dist-upgrade
Simulate an upgrade
3
apt-cache policy <pkg>
View versions and priorities
4
apt-file search <file>
Find the providing package
5
sudo apt build-dep <pkg>
Install build dependencies
6
apt-mark hold <pkg>
Lock a package
7
apt-cache rdepends <pkg>
View dependents
8
deborphan | xargs sudo apt purge -y
Purge orphaned packages
9
dpkg -S <file>
Find which package owns a file
10
aptitude search '~S'
Advanced search with patterns
11
sudo needrestart
Restart services after update
12
apt-cache madison <pkg>
All available versions

🎯 Advanced Practical Cases (GPS format)

A1
Install a package from backports
Problem
Version too old
Command
sudo apt install -t trixie-backports firefox
A2
Recover a system with broken dependencies
Command
sudo apt --fix-broken install
A3
Minimal installation
Command
sudo apt install --no-install-recommends nginx
A4
Clean downgrade
Command
sudo apt install <pkg>=<old-version>
A5
Find the providing package
Command
apt-file search bin/lsmod
A6
Check consistency
Commands
sudo apt check + sudo debsums -c
A7
Simulate a risky removal
Command
apt remove --simulate libssl
A8
Lock the kernel
Command
sudo apt-mark hold linux-image-amd64
A9
See what depends on python3
Command
apt-cache rdepends --installed python3
A10
Build dependencies
Command
sudo apt build-dep vlc
A11
Clean orphaned packages
Command
sudo apt autoremove --purge
A12
Check bugs before installation
Command
apt-listbugs list apache2

🔗 Complete References

Official Debian Documentation

SourceContent
aptComplete reference for the apt command
aptitudeComplete reference for aptitude
apt-getComplete reference for apt-get
Aptitude vs. Apt-GetComparison and package authentication

Local Help Pages

Help
$apt install --help
$apt-get install --help
$apt search --help
$apt search --help
$apt remove --help
$apt-get remove --help
$aptitude --help

📖 Recommended Reads — SafeITExperts

SourceContent
sudo vs suComplete Guide to Linux Privilege Elevation
Desktop Environment CompatibilitiesLinux Desktop Environment Compatibilities in 2025
Enable KDE Unstable Plasma on openSUSEKDE Plasma on openSUSE Tumbleweed
Linux, Windows or macOS8 Essential Criteria to Choose Your OS

🎯 Conclusion

APT is a powerful and mature tool that is one of Debian's greatest strengths. Mastering it requires understanding repositories, pinning, and the various commands available.

Key Points
  • Stableapt upgrade ; Testing/Sidapt full-upgrade
  • Always run apt update before installing
  • Use --simulate to preview
  • Configure pinning to control priorities
  • Clean up with apt autoremove and apt autoclean
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article

Archives

Articles récents