Product SiteDocumentation Site

Capitolo 6. Manutenzione ed aggiornamento: gli strumenti APT

6.1. Compilazione del file sources.list
6.1.1. Sintassi
6.1.2. Repository per gli utenti di Stable
6.1.3. Repository per gli utenti di Testing/Unstable
6.1.4. Using Alternate Mirrors
6.1.5. Risorse Non Ufficiali: mentors.debian.net
6.1.6. Proxy con cache per i pacchetti Debian
6.2. I Comandi aptitude, apt-get, e apt
6.2.1. Inizializzazione
6.2.2. Installazione e rimozione
6.2.3. Aggiornamento del sistema
6.2.4. Opzioni di configurazione
6.2.5. Gestire le priorità dei pacchetti
6.2.6. Lavorare con più distribuzioni
6.2.7. Tenere traccia dei pacchetti installati automaticamente
6.3. Il comando apt-cache
6.4. The apt-file Command
6.5. Frontend: aptitude, synaptic
6.5.1. aptitude
6.5.2. synaptic
6.6. Controllare l'autenticità dei pacchetti
6.7. Aggiornare da una distribuzione stabile alla successiva
6.7.1. Procedura raccomandata
6.7.2. Gestire i problemi dopo un aggiornamento
6.7.3. Cleaning Up after an Upgrade
6.8. Mantenere un sistema sempre aggiornato
6.9. Aggiornamenti automatici
6.9.1. Configurare dpkg
6.9.2. Configurare APT
6.9.3. Configurare debconf
6.9.4. Gestire interazioni a riga di comando
6.9.5. La combinazione miracolosa
6.10. Ricercare pacchetti
What makes Debian so popular with administrators is how easily software can be installed and how easily the whole system can be updated. This unique advantage is largely due to the APT program, which Falcot Corp administrators studied with enthusiasm.
APT is the abbreviation for Advanced Package Tool. What makes this program “advanced” is its approach to packages. It doesn't simply evaluate them individually, but it considers them as a whole and produces the best possible combination of packages depending on what is available and compatible according to dependencies.
APT needs to be given a “list of package sources (repositories)”: the file /etc/apt/sources.list will list the different repositories that publish Debian packages. APT will then import the list of packages published by each of these sources. This operation is achieved by downloading Packages.xz files or a variant such as Packages.gz or .bz2 (using a different compression method) in case of a source of binary packages and by analyzing their contents. In case of a source of source packages, APT downloads Sources.xz files or a variant using a different compression method. When an old copy of these files is already present, APT can update it by only downloading the differences (see sidebar TIP Incremental updates).

6.1. Compilazione del file sources.list

6.1.1. Sintassi

Each active line in the /etc/apt/sources.list file represents a package source (repository) and is made of at least three parts separated by spaces. For a complete description of the file format and the accepted entry compositions see sources.list(5).

Esempio 6.1. Example entry format in /etc/apt/sources.list

deb url distribution component1 component2 component3 [..] componentX
deb-src url distribution component1 component2 component3 [..] componentX
Il primo campo indica il tipo di sorgente:
deb
package source (repository) of binary packages
deb-src
package source (repository) of source packages
The second field gives the base URL of the source. Combined with the filenames listed in the Packages.xz files, it must give a full and valid URL. This can consist in a Debian mirror or in any other package archive set up by a third party. The URL can start with file:// to indicate a local source installed in the system's file hierarchy, with http:// or https:// to indicate a source accessible from a web server server, or with ftp:// or ftps:// for a source available on an FTP server. The URL can also start with cdrom: for CD-ROM/DVD/Blu-ray disc based installations, although this is less frequent, since network-based installation methods are eventually more common.
The syntax of the last field depends on the structure of the repository. In the simplest case, you can simply indicate a subdirectory (with a required trailing slash) of the desired source. This is often a simple “./” which refers to the absence of a subdirectory. The packages are then directly at the specified URL. But in the most common case, the repositories will be structured like a Debian mirror, with multiple distributions, each having multiple components. In those cases, name the chosen distribution by its “codename” — see the list in sidebar COMUNITÀ Bruce Perens, un leader controverso — or by the corresponding “suite” oldstable, stable, testing, unstable) and then the components to enable. A typical Debian mirror provides the components main, contrib, and non-free.
Le voci cdrom descrivono i CD/DVD-ROM che si possiedono. Contrariamente alle altre voci un CD-ROM non è sempre disponibile in quanto deve essere inserito nell'unità e dato che può essere letto solo un disco alla volta. Per questi motivi, queste sorgenti sono gestite in maniera leggermente differente e devono essere aggiunte con il programma apt-cdrom, solitamente eseguito con il parametro add. Quest'ultimo chiederà di inserire il disco nel lettore e cercherà nel contenuto alla ricerca dei file Packages. Questi file saranno usati per aggiornare il database dei pacchetti disponibili (questa operazione di norma è fatta dal comando apt update). Da quel momento in poi, APT può richiedere di inserire il disco se avrà bisogno di uno dei suoi pacchetti.

6.1.2. Repository per gli utenti di Stable

Questo è un sources.list per un sistema che utilizza la versione Stable di Debian:

Esempio 6.2. File /etc/apt/sources.list per gli utenti di Debian Stable

# Security updates
deb http://security.debian.org/ buster/updates main contrib non-free
deb-src http://security.debian.org/ buster/updates main contrib non-free

## Debian mirror

# Base repository
deb https://deb.debian.org/debian buster main contrib non-free
deb-src https://deb.debian.org/debian buster main contrib non-free

# Stable updates
deb https://deb.debian.org/debian buster-updates main contrib non-free
deb-src https://deb.debian.org/debian buster-updates main contrib non-free

# Stable backports
deb https://deb.debian.org/debian buster-backports main contrib non-free
deb-src https://deb.debian.org/debian buster-backports main contrib non-free
This file lists all sources of packages associated with the Buster version of Debian (the current Stable suite as of this writing). In the example above, we opted to name “buster” explicitly instead of using the corresponding “stable“ aliases (stable, stable-updates, stable-backports) because we don't want to have the underlying distribution changed outside of our control when the next stable release comes out.
La maggior parte di pacchetti proviene dal «repository base» che contiene tutti i pacchetti ma che viene aggiornato di rado (circa una volta ogni 2 mesi per un «rilascio minore»). Gli altri repository sono parziali (non contengono tutti i pacchetti) e possono ospitare aggiornamenti (pacchetti con versioni più recenti) che APT può installare. Le sezioni seguenti spiegheranno lo scopo di ognuno di questi repository e le regole che lo governano.
Notare che, quando la versione desiderata di un pacchetto è disponibile su diversi repository, verrà usato quello elencato per primo nel file sources.list. Per questa ragione, le sorgenti non ufficiali vengono solitamente aggiunte alla fine del file.
Notare anche che la maggior parte di ciò che questa sezione dice riguardo a Stable vale allo stesso modo per Oldstable, dato che quest'ultima non è altro che una più vecchia versione Stable che viene mantenuta in parallelo.

6.1.2.1. Aggiornamenti di sicurezza

Debian takes security seriously. Known software vulnerabilities in Debian are tracked in the Security Bug Tracker and usually get fixed in a reasonable timeframe. The security updates are not hosted on the usual network of Debian mirrors but on security.debian.org, a small set of machines maintained by the Debian System Administrators. This archive contains security updates prepared by the Debian Security Team and/or by package maintainers for the Stable and Oldstable distribution.
The server can also host security updates for Testing but this doesn't happen very often since those updates tend to reach the Testing suite via the regular flow of updates coming from Unstable.
For serious issues, the security team issues a Debian Security Advisory (DSA) and announces it together with the security update on the mailing list (archive).

6.1.2.2. Aggiornamenti di Stable

Gli aggiornamenti di Stable non sono relativi alla sicurezza, ma vengono considerati sufficientemente importanti da essere passati agli utenti prima del successivo rilascio minore di stable.
This repository will typically contain fixes for critical and serious bugs which could not be fixed before release or which have been introduced by subsequent updates. Depending on the urgency, it can also contain updates for packages that have to evolve over time, like spamassassin's spam detection rules, clamav's virus database, the daylight-saving time rules of all timezones (tzdata), the ESR version of Firefox (firefox-esr) or cryptographic keyrings like debian-archive-keyring.
In practice, this repository is a subset of the proposed-updates repository, carefully selected by the Stable Release Managers. All updates are announced on the mailing list (archive) and will be included in the next Stable point release anyway.
deb https://deb.debian.org/debian buster-updates main contrib non-free

6.1.2.3. Aggiornamenti proposti

Una volta pubblicata, la distribuzione Stable viene aggiornata solo ogni 2 mesi circa. Il repository proposed-updates è il luogo in cui gli aggiornamenti pianificati vengono preparati (sotto la supervisione dei Stable Release Manager).
Gli aggiornamenti di sicurezza e quelli di stable documentati nelle sezioni precedenti sono sempre inclusi in questo repository, ma c'è anche di più, perché i manutentori di pacchetti hanno anche l'opportunità di risolvere importanti bug che non meritano un rilascio immediato.
Anyone can use this repository to test those updates before their official publication. The extract below uses the buster-proposed-updates alias which is both more explicit and more consistent since stretch-proposed-updates also exists (for the Oldstable updates):
deb https://deb.debian.org/debian buster-proposed-updates main contrib non-free

6.1.2.4. Backport per Stable

Il repository stable-backports ospita i «backport di pacchetti». Questa espressione si riferisce ad un pacchetto di un qualche software recente che è stato ricompilato per una distribuzione più vecchia, generalmente per Stable.
When the distribution becomes a little dated, numerous software projects have released new versions that are not integrated into the current Stable suite, which is only modified to address the most critical problems, such as security issues. Since the Testing and Unstable suites can be more risky, package maintainers sometimes voluntarily offer recompilations of recent software applications for Stable, which has the advantage to users and system administrators to limit potential instability to a small number of chosen packages. The page https://backports.debian.org provides more information.
Backports from stable-backports are only created from packages available in Testing. This ensures that all installed backports will be upgradable to the corresponding stable version once the next stable release of Debian is available.
Even though this repository provides newer versions of packages, APT will not install them unless you give explicit instructions to do so (or unless you have already done so with a former version of the given backport):
$ sudo apt-get install package/buster-backports
$ sudo apt-get install -t buster-backports package

6.1.3. Repository per gli utenti di Testing/Unstable

Questo è un file sources.list standard per un sistema che utilizza la versione Testing o Unstable di Debian:

Esempio 6.3. File /etc/apt/sources.list per gli utenti di Debian Testing/Unstable

# Unstable
deb https://deb.debian.org/debian unstable main contrib non-free
deb-src https://deb.debian.org/debian unstable main contrib non-free

# Testing
deb https://deb.debian.org/debian testing main contrib non-free
deb-src https://deb.debian.org/debian testing main contrib non-free

# Testing security updates
deb http://security.debian.org/ testing-security main contrib non-free
deb-src http://security.debian.org/ testing-security main contrib non-free

# Stable
deb https://deb.debian.org/debian stable main contrib non-free
deb-src https://deb.debian.org/debian stable main contrib non-free

# Stable security updates
deb http://security.debian.org/ stable/updates main contrib non-free
deb-src http://security.debian.org/ stable/updates main contrib non-free
With this sources.list file APT will install packages from the Unstable suite. If that is not desired, use the APT::Default-Release setting (see Sezione 6.2.3, «Aggiornamento del sistema») to instruct APT to pick packages from another suite (most likely Testing in this case).
Ci sono buone ragioni per includere tutti questi repository, anche se uno solo dovrebbe essere sufficiente. Gli utenti di Testing apprezzeranno la possibilità di scegliere individualmente un particolare pacchetto da Unstable quando la versione in Testing è affetta da un bug noioso. D'altro canto, gli utenti di Unstable colpiti da regressioni inaspettate hanno la possibilità di retrocedere pacchetti alla loro versione in Testing (che si suppone funzionante).
The inclusion of Stable is more debatable but it often gives access to some packages, which have been removed from the development versions. It also ensures that you get the latest updates for packages, which have not been modified since the last stable release.

6.1.3.1. I repository Experimental

L'archivio dei pacchetti Experimental è presente in tutti i mirror Debian, e contiene i pacchetti che non sono ancora nella distribuzione Unstable a causa della loro qualità inferiore agli standard — spesso sono versioni di sviluppo o pre-versioni (alfa, beta, candidata al rilascio...). Un pacchetto può anche essere inserito lì dopo aver subito modifiche che possono generare problemi. Il manutentore quindi cerca di scoprirli grazie all'aiuto di utenti esperti in grado di gestire problemi importanti. Dopo questa prima fase, il pacchetto viene spostato in Unstable, dove raggiunge un pubblico molto più grande e dove verrà testato in modo molto più dettagliato.
Experimental è generalmente usata dagli utenti a cui non importa rovinare il proprio sistema e ripararlo. Questa distribuzione offre la possibilità di importare un pacchetto che un utente vuol provare o utilizzare in caso di necessità. Questo è esattamente come Debian lo tratta, in quanto aggiungerlo nel file sources.list di APT non porta all'uso sistematico dei suoi pacchetti. La riga da aggiungere è:
deb https://deb.debian.org/debian experimental main contrib non-free

6.1.4. Using Alternate Mirrors

The sources.list examples in this chapter refer to package repositories hosted on deb.debian.org. Those URLs will redirect you to servers which are close to you and which are managed by Content Delivery Networks (CDN) whose main role is to store multiple copies of the files across the world, and to deliver them as fast as possible to users. The CDN companies that Debian is working with are Debian partners who are offering their services freely to Debian. While none of those servers are under direct control of Debian, the fact that the whole archive is sealed by GPG signatures makes it a non-issue.
Picky users who are not satisfied with the performance of deb.debian.org can try to find a better mirror in the official mirror list:
But when you don't know which mirror is best for you, this list is of not much use. Fortunately for you, Debian maintains DNS entries of the form ftp.country-code.debian.org (e.g. ftp.us.debian.org for the USA, ftp.fr.debian.org for France, etc.) which are covering many countries and which are pointing to one (or more) of the best mirrors available within that country.
As an alternative to deb.debian.org, there used to be httpredir.debian.org. This service would identify a mirror close to you (among the list of official mirrors, using GeoIP mainly) and would redirect APT's requests to that mirror. This service has been deprecated due to reliability concerns and now httpredir.debian.org provides the same CDN-based service as deb.debian.org.

6.1.5. Risorse Non Ufficiali: mentors.debian.net

There are numerous non-official sources of Debian packages set up by advanced users who have recompiled some software (Ubuntu made this popular with their Personal Package Archive (PPA) service, by programmers who make their creation available to all, and even by Debian developers who offer pre-versions of their package online.
The mentors.debian.net site is interesting (although it only provides source packages), since it gathers packages created by candidates to the status of official Debian developer or by volunteers who wish to create Debian packages without going through that process of integration. These packages are made available without any guarantee regarding their quality; make sure that you check their origin and integrity and then test them before you consider using them in production.
Installare un pacchetto significa dare i privilegi di root al suo creatore, perché può decidere i contenuti degli script di inizializzazione i quali sono lanciati sotto tale identità. I pacchetti Debian ufficiali sono creati da volontari che sono stati selezionati e vagliati e che possono mettere un sigillo ai loro pacchetti così che la loro origine e integrità possa essere controllata.
In general, be wary of a package whose origin you don't know and which isn't hosted on one of the official Debian servers: evaluate the degree to which you can trust the creator, and check the integrity of the package.

6.1.6. Proxy con cache per i pacchetti Debian

Quando un'intera rete di macchine è configurata in moda da usare lo stesso server remoto per scaricare gli stessi pacchetti aggiornati, qualsiasi amministratore sa che sarebbe vantaggioso avere un proxy intermedio che agisce da cache locale per la rete (vedere il riquadro VOCABOLARIO Cache).
Si può configurare APT in modo che usi un proxy «standard» (vedere la Sezione 6.2.4, «Opzioni di configurazione» per la parte riguardante APT e la Sezione 11.6, «Proxy HTTP/FTP» per la parte proxy), ma l'ecosistema Debian offre opzioni migliori per risolvere il problema. Il software dedicato presentato in questa sezione è più intelligente di un semplice proxy con cache perché può fare affidamento sulla struttura specifica dei repository APT (per esempio sa quando singoli file sono obsoleti oppure no, e perciò regola il tempo per il quale vengono conservati).
apt-cacher e apt-cacher-ng funzionano come i normali server proxy con cache. Il file sources.list di APT resta invariato, ma APT viene configurato in modo da usarli come proxy per le richieste in uscita.
approx, invece, agisce come un server HTTP che fa da "mirror" per qualsiasi numero di repository remoti nei suoi URL di più alto livello. La mappatura tra queste directory di più alto livello e gli URL remoti dei repository viene memorizzata in /etc/approx/approx.conf:
# <name> <repository-base-url>
debian   https://deb.debian.org/debian
security http://security.debian.org
approx runs by default on port 9999 via a systemd socket and requires the users to adjust their sources.list file to point to the approx server:
# Sample sources.list pointing to a local approx server
deb http://localhost:9999/security buster/updates main contrib non-free
deb http://localhost:9999/debian buster main contrib non-free