6.2. Los programas aptitude
, apt-get
y apt
APT es un proyecto gigante y su plan original incluia una interfaz gráfica. Está basado en una biblioteca que contiene la aplicación central y apt-get
fue la primera interfaz — basada en la línea de órdenes — desarrollada dentro del proyecto. apt
es un segundo frontend de linea de comandos proporcionado por APT el cual soluciona algunos errores de diseño de la orden apt-get
.
Numerous other graphical interfaces then appeared as external projects: synaptic
, aptitude
(which includes both a text mode interface and a graphical one — even if not complete yet), wajig
, etc. The most recommended interface, apt
, is the one that we will use in the examples given in this section. Note however that apt-get
and aptitude
have a very similar command line syntax. When there are major differences between apt
, apt-get
and aptitude
, these differences will be detailed.
Para cualquier trabajo con APT necesita actualizar la lista de paquetes; puede hacer esto simplemente con apt update
. Dependiendo de la velocidad de su conexión esta operación puede demorar ya que involucra descargar una cantidad de archivos Packages
/Sources
/Translation-codigo-idioma
que han crecido gradualmente a medida que se desarrolló Debian (más de 10 MB de datos para la sección main
). Por su puesto, instalar desde un CD-ROM no requiere descarga alguna — en ese caso esta operación es muy rápida.
6.2.2. Instalación y eliminación
Con APT puede agregar o eliminar paquetes del sistema, con apt install paquete
y apt remove paquete
respectivamente. En ambos casos APT automáticamente instalará las dependencias necesarias o eliminará los paquetes que dependen del paquete que está siendo eliminado. La orden ap purge paquete
realiza una desinstalación completa — se eliminan también los archivos de configuración.
If the file
sources.list
mentions several distributions, it is possible to give the version of the package to install. A specific version number can be requested with
apt install package=version
, but indicating its distribution of origin (
Stable,
Testing or
Unstable) — with
apt install package/distribution
— is usually preferred. With this command, it is possible to go back to an older version of a package (if for instance you know that it works well), provided that it is still available in one of the sources referenced by the
sources.list
file. Otherwise the
snapshot.debian.org
archive can come to the rescue (see sidebar
YENDO MÁS ALLÁ Versiones antiguas de paquetes: snapshot.debian.org
).
Ejemplo 6.3. Instalación de la versión en Unstable de spamassassin
#
apt install spamassassin/unstable
6.2.3. Actualización del sistema
Regular upgrades are recommended, because they include the latest security updates. To upgrade, use apt upgrade
, apt-get upgrade
or aptitude safe-upgrade
(of course after apt update
). This command looks for installed packages which can be upgraded without removing any packages. In other words, the goal is to ensure the least intrusive upgrade possible. apt-get
is slightly more demanding than aptitude
or apt
because it will refuse to install packages which were not installed beforehand.
apt
will generally select the most recent version number (except for packages from Experimental and stable-backports, which are ignored by default whatever their version number). If you specified Testing or Unstable in your sources.list
, apt upgrade
will switch most of your Stable system to Testing or Unstable, which might not be what you intended.
To tell apt
to use a specific distribution when searching for upgraded packages, you need to use the -t
or --target-release
option, followed by the name of the distribution you want (for example: apt -t stable upgrade
). To avoid specifying this option every time you use apt
, you can add APT::Default-Release "stable";
in the file /etc/apt/apt.conf.d/local
.
For more important upgrades, such as the change from one major Debian version to the next, you need to use apt full-upgrade
. With this instruction, apt
will complete the upgrade even if it has to remove some obsolete packages or install new dependencies. This is also the command used by users who work daily with the Debian Unstable release and follow its evolution day by day. It is so simple that it hardly needs explanation: APT's reputation is based on this great functionality.
Unlike apt
and aptitude
, apt-get
doesn't know the full-upgrade
command. Instead, you should use apt-get dist-upgrade
(”distribution upgrade”), the historical and well-known command that apt
and aptitude
also accept for the convenience of users who got used to it.
6.2.4. Opciones de configuración
Besides the configuration elements already mentioned, it is possible to configure certain aspects of APT by adding directives in a file of the /etc/apt/apt.conf.d/
directory. Remember for instance that it is possible for APT to tell dpkg
to ignore file conflict errors by specifying DPkg::options { "--force-overwrite"; }
.
Si sólo puede acceder a la web a través de un proxy, agregue una línea como
Acquire::http::proxy "http://su-proxy:3128"
. Para un proxy FTP, utilice
Acquire::ftp::proxy "ftp://su-proxy"
. Para descubrir más opciones de configuración, lea la página de manual
apt.conf(5) con la orden
man apt.conf
(para detalles sobre las páginas de manual, revise la
Sección 7.1.1, “Páginas de manual”).
6.2.5. Gestión de prioridades de los paquetes
Uno de los aspectos más importantes en la configuración de APT es la gestión de las prioridades asociadas con cada origen de paquetes. Por ejemplo, podría desear extender una distribución con uno o dos paquetes más recientes de Testing, Unstable o Experimental. Es posible asignar una prioridad a cada paquete disponible (el mismo paquete puede tener varias prioridades según su versión o la distribución que lo provee). Estas prioridades influenciarán el comportamiento de APT: para cada paquete, siempre seleccionará la versión con la prioridad más alta (excepto si esta versión es anterior a la instalada y si su prioridad es menor a 1000).
APT define varias prioridades predeterminadas. Cada versión instalada de un paquete tiene una prioridad de 100. Una versión no instalada tiene una prioridad predeterminada de 500, pero puede saltar a 990 si es parte de la distribución destino (definida con la opción de línea de órdenes -t
o la directiva de configuración APT::Default-Release
).
Puede modificar las prioridades agregando elementos en el archivo /etc/apt/preferences
con los nombres de los paquetes afectados, sus versiones, sus orígenes y sus nuevas prioridades.
APT nunca instalará una versión anterior de un paquete (esto es, un paquete cuyo número de versión sea menor al que está instalado actualmente) excepto si su prioridad es mayor a 1000. APT siempre instalará el paquete con la mayor prioridad que cumpla esta restricción. Si dos paquetes tienen la misma prioridad, APT instalará la más reciente (aquella cuya versión sea mayor). Si dos paquetes de la misma versión tienen la misma prioridad pero tienen diferente contenido, APT instalará la versión que no está instalada (se creó esta regla para cubrir los casos de la actualización de un paquete sin aumentar el número de revisión, que es generalmente necesario).
En términos más concretos, un paquete con prioridad menor a 0 nunca será instalado. Un paquete con una prioridad entre 0 y 100 sólo será instalado si no hay otra versión ya instalada del paquete. Con una prioridad entre 100 y 500, el paquete sólo será instalado si no hay otra versión más reciente instalada o disponible en otra distribución. Un paquete con prioridad entre 501 y 990 será instalado sólo si no hay una versión más nueva instalada o disponible en la distribución de destino. Con una prioridad entre 990 y 1000, el paquete será instalado a menos que la versión instalada sea mayor. Una prioridad mayor a 1000 siempre llevará a la instalación del paquete aún si ésto significa que APT instalará una versión anterior.
When APT checks /etc/apt/preferences
, it first takes into account the most specific entries (often those specifying the concerned package), then the more generic ones (including for example all the packages of a distribution). If several generic entries exist, the first match is used. The available selection criteria include the package's name and the source providing it. Every package source is identified by the information contained in a Release
file that APT downloads together with the Packages
files. It specifies the origin (usually “Debian” for the packages of official mirrors, but it can also be a person's or an organization's name for third-party repositories). It also gives the name of the distribution (usually Stable, Testing, Unstable or Experimental for the standard distributions provided by Debian) together with its version (for example 8 for Debian Jessie). Let's have a look at its syntax through some realistic case studies of this mechanism.
Supongamos que sólo desea utilizar paquetes de la versión estable de Debian. Aquellos provistos en otras versiones no serían instalados a menos que sean pedidos explícitamente. Puede escribir las siguientes entradas en el archivo /etc/apt/preferences
:
a=stable
define el nombre de la distribución elegida. o=Debian
limita el alcance a los paquetes cuyo origen es «Debian».
Let's now assume that you have a server with several local programs depending on the version 5.14 of Perl and that you want to ensure that upgrades will not install another version of it. You could use this entry:
La documentación de referencia para este archivo de configuración está disponible en la página de manual apt_preferences(5) que puede ver con man apt_preferences
.
6.2.6. Trabajo con varias distribuciones
apt
being such a marvelous tool, it is tempting to pick packages coming from other distributions. For example, after having installed a Stable system, you might want to try out a software package available in Testing or Unstable without diverging too much from the system's initial state.
Even if you will occasionally encounter problems while mixing packages from different distributions,
apt
manages such coexistence very well and limits risks very effectively. The best way to proceed is to list all distributions used in
/etc/apt/sources.list
(some people always put the three distributions, but remember that
Unstable is reserved for experienced users) and to define your reference distribution with the
APT::Default-Release
parameter (see
Sección 6.2.3, “Actualización del sistema”).
Let's suppose that Stable is your reference distribution but that Testing and Unstable are also listed in your sources.list
file. In this case, you can use apt install package/testing
to install a package from Testing. If the installation fails due to some unsatisfiable dependencies, let it solve those dependencies within Testing by adding the -t testing
parameter. The same obviously applies to Unstable.
In this situation, upgrades (
upgrade
and
full-upgrade
) are done within
Stable except for packages already upgraded to another distribution: those will follow updates available in the other distributions. We will explain this behavior with the help of the default priorities set by APT below. Do not hesitate to use
apt-cache policy
(see sidebar
SUGERENCIA apt-cache policy
) to verify the given priorities.
Todo gira alrededor del hecho de que APT considera sólo paquetes con una versión mayor o igual que la instalada (suponiendo que /etc/apt/preferences
no ha sido usado para forzar prioridades superiores a 1000 para algunos paquetes).
Asumamos que instaló la versión 1 de un primer paquete de Stable y que las versiones 2 y 3 están disponibles en Testing y Unstable respectivamente. La versión instalada tiene una prioridad de 100, pero la versión disponible en Stable (la misma versión) tiene una prioridad de 990 (porque es parte de la versión de destino). Los paquetes en Testing y Unstable tienen una prioridad de 500 (la prioridad predeterminada para una versión no instalada). El ganador es, por lo tanto, la versión 1 con una prioridad de 990. El paquete «se mantiene en Stable».
Tomemos como ejemplo otro paquete cuya versión 2 fue instalada de Testing. La versión 1 está disponible en Stable y la versión 3 en Unstable. La versión 1 (de prioridad 990 — por lo tanto menor a 1000) es descartada porque es menor que la versión instalada. Esto deja sólo las versiones 2 y 3, ambas de prioridad 500. Frente a esta alternativa, APT selecciona la versión más nueva: la de Unstable. Si no desea que un paquete de Testing actualice su versión a la de Unstable, debe asignar una prioridad menor a 500 (490 por ejemplo) a los paquetes que provengan de Unstable. Puede modificar /etc/apt/preferences
de la siguiente forma:
Package: *
Pin: release a=unstable
Pin-Priority: 490
6.2.7. Seguimiento de paquetes instalados automáticamente
One of the essential functionalities of apt
is the tracking of packages installed only through dependencies. These packages are called “automatic”, and often include libraries for instance.
With this information, when packages are removed, the package managers can compute a list of automatic packages that are no longer needed (because there is no “manually installed” packages depending on them). apt-get autoremove
will get rid of those packages. aptitude
and apt
do not have this command: the former because it removes them automatically as soon as they are identified, and the latter probably because the user should not have to manually run such a command. In all cases, the tools display a clear message listing the affected packages.
Es buen hábito marcar como automático cualquier paquete que no necesite directamente para que sea eliminado automáticamente cuando ya no sea necesario.
apt-mark auto paquete
marcará el paquete dado como automático mientras que
apt-mark manual paquete
realiza lo opuesto.
aptitude markauto
y
aptitude unmarkauto
funcionan de la misma forma, pero ofrecen más funcionalidad para marcar varios paquetes simultáneamente (revise la
Sección 6.4.1, “aptitude
”). La interfaz interactiva para la consola de
aptitude
también facilita el revisar la «marca automática» en muchos paquetes.
People might want to know why an automatically installed package is present on the system. To get this information from the command line, you can use aptitude why package
(apt
and apt-get
have no similar feature):
$
aptitude why python-debian
i aptitude Recommends apt-xapian-index
i A apt-xapian-index Depends python-debian (>= 0.1.15)