Inizio  >  Docs  >  Linux  >  Trucchi veloci  >  Package Manager  
Package ManagerPackage Manager

Index

dpkg(Good), apt(Better) and aptitude(Best)


dpkg

Debian uses dpkg to install, remove and do everything else related to debian(.deb) packages.

Some basic dpkg commands include:

Install a package, usually a package you downloaded from somewhere else other than apt(more on apt later) mirrors:

dpkg -i package.deb

Remove a package:

dpkg -r package

Purge a package, it removes everything belonging to the package... including configuration files:

dpkg -P package

List installed packages:

dpkg --get-selections

or

dpkg -l

or to only show installed packages:

dpkg -l | grep ^ii

To reconfigure a installed package, for instance X.Org:

dpkg-reconfigure xserver-xorg

dpkg is powerfull but it doenst handle dependencies among other things, for that you have to(and you will) use one of its frontends like apt, aptitude, synaptic(needs X), and others.

P.S. dpkg doesn't handle dependencies but... if you need to install a .deb that has a lot of them you can use gdebi(after you install it of course):

gdebi mypackage.deb

It will install the .deb plus all the dependencies it needs, as long as they exist in the apt archives(defined by <code>/etc/apt/sources.list</code>).

All those frontends have a couple of things in common and some of them they share. On of the things they share is <code>/etc/apt/sources.list</code>, this file lists the apt mirrors you want to use(official or otherwise). Check "my" sources.list for some examples/tips.

 

apt (Advanced Packaging Tool)

apt has two main utils, apt-get to handle packages(install, remove, etc) and apt-cache to handle the packages cache(search, stats, etc)

Both of this programs are simple to use and a <code>apt-get --help</code> or <code>apt-cache --help</code> should be more than enough but here goes:

Update package list; should be done everyday, specially if you use unstable or testing, or everytime you change your sources.list:

apt-get update

Upgrade all installed packages; should be used after and an <code>apt-get update</code>:

apt-get upgrade

Install packages:

apt-get install package

Remove packages:

apt-get remove package

Purge(remove package and configuration):

apt-get --purge remove package

You can handle several packages at the same time, for instance:

apt-get install package1 package2 package3

If you want to install every package that includes gnome on their name then:

apt-get install 'gnome-.*'

<code>--purge</code> is an option but there are others like <code>-d</code> for downloading packages but not installing them, in case you want to install them later; <code>-s</code> for simulating the operation, this way you can check what apt will do before it really does anything.

Upgrading to a different Debian distribution, there are 3 main distribuitons in Debian: stable, testing and unstable. And then there is experimental...; for instance from stable to testing, this will upgrade your Debian system to the testing distribution. Remember first you must have a testing source in <code>/etc/apt/sources.list</code>:

apt-get dist-upgrade

Every package apt downloads is kept in <code>/var/cache/apt/archives/</code> and <code>/var/cache/apt/archives/partial</code>(since apt supports resume, packages not fully downloaded are kept here), that means that directory can fill up quite fast, for that apt provides two options... clean and autoclean.

clean; it deletes every package in <code>/var/cache/apt/archives/</code> and <code>/var/cache/apt/archives/partial</code>:

apt-get clean

autoclean; similar to the clean option but only deletes old, useless, packages:

apt-get autoclean

I alredy talked about the basics on handling packages, but you can't really do much if you don't know the package names, that's where apt-cache comes in...

Search a package; this will search for the string(gnome in this case) in the entire database, package names, descriptions, etc:

apt-cache search gnome

or to search for packages that include gnome and audio:

apt-cache search gnome audio

As you can see that gives a lot of results, so if you only want to search packages that include "gnome" in their name just use:

apt-cache search gnome --names-only

Another common task of apt-cache is to show package information, like dependencies, versions and description:

apt-cache show package

 

aptitude

aptitude is based on apt so most of the functions are the same as in apt, but it combines apt-get and apt-cache into the same program with some some new features.

Update package list:

aptitude update

Upgrade all installed packages:

aptitude upgrade

Upgrade all installed packages but be more agressive on resolving dependecies, can remove and install new packages. It's also used to upgrade from a distribution to another(say from stable to testing):

aptitude dist-upgrade

Install packages:

aptitude install package

Remove packages:

aptitude remove package

Remove packages and it's configurations:

aptitude purge package

Show package description and detailed information

aptitude show package

See the changelog of a package, in this case we will check the changelog of gnome-games in experimental:

aptitude changelog gnome-games/experimental

As in apt, aptitude can also handle several packages at the same time, for instance:

aptitude install package1 package2 package3

aptitude search is a bit different...

Search for packages that include the string gnome(for example) in their name:

aptitude search gnome

Search for packages than include gnome in their description:

aptitude search ~dgnome

You can also search by version <code>~V</code>, maintainer <code>~m</code>, etc.

To list all installed packages:

aptitude search ~i

Or to list all installed packages that contain gnome on their name:

aptitude search ~ignome

Check for packages available on experimental(as long as you have a source for it):

aptitude search ~Aexperimental

List removed packages that weren't purged, their configurations still exist on your system:

aptitude search ~c

If you want to delete ALL those configs do:

dpkg --get-selections | awk '/deinstall$|purge$/{print $1}' |xargs dpkg -P

One of the new features,of aptitude, is logging every action, the logs are kept in <code>/var/log/aptitude</code>.

Thanks to logging package management is more efficient, it removes dependencies when you remove the package that installed them. That is great for metapackages (a metapackage is a list of packages needed for a certain task)

For example let's remove gnome-games, with apt we would get the following:

sueca:/home/anarka# apt-get --purge remove gnome-games
Reading package lists... Done
Building dependency tree... Done
The following packages will be REMOVED:
gnome-games*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0B of archives.
After unpacking 1697kB disk space will be freed.
Do you want to continue [Y/n]?

Nice gnome-games package is removed but nothing else, now let's try with aptitude:

sueca:/home/anarka# aptitude purge gnome-games
Reading package lists... Done
Building dependency tree... Done
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
Building tag database... Done
The following packages are unused and will be REMOVED:
gnome-games-data [1:2.12.1-1] gnome-games-extra-data [2.12.0-1] guile-1.6-libs [1.6.7-1.1]
libguile-ltdl-1 [1.6.7-1.1] libqthreads-12 [1.6.7-1.1] librsvg2-common [2.12.7-1]
The following packages will be REMOVED:
gnome-games{p} [1:2.12.1-1]
0 packages upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 22.2MB will be freed.
Do you want to continue? [Y/n/?] n

This is much more efficient, not only it removes gnome-games, but it also removes packages that aren't needed anymore due to the removal of the package. Of course if you want good results you should only use aptitude, since apt doesn't log anything, so you can't just hope aptitude will know what you did with apt.

If you want to customize apt or aptitude use <code>/etc/apt/apt.conf</code>, i have the following lines in there:

APT::Get::Show-Upgraded "true";
APT::Acquire::Retries "5";
APT::Cache-Limit 22582912;
APT::Get::Purge;
Aptitude::CmdLine::Show-Versions "true";
Aptitude::CmdLine::Verbose "5";
Aptitude::CmdLine::Always-Prompt "true";
Aptitude::CmdLine::Package-Display-Format "%c%a%M %p# %15v %15V - %d#";

Updated in 2006/07/23 anarka(at)anarka.org

To top

apt-get dpkg etc.

Oggi vista l’antipatia che spesso si registra in molti blog o forum verso l’uso del terminale voglio appuntare in questo post alcuni comandi inerenti l’uso di APT-GET.
Advanced Packaging Tool, conosciuto con l’acronimo APT, è il gestore standard di pacchetti software della distribuzione Debian. Un gestore di pacchetti viene utilizzato per installare, aggiornare, verificare e rimuovere software del sistema operativo in maniera intuitiva e aiuta a risolvere le dipendenze tra i pacchetti. APT ha la particolarità di sfruttare contemporaneamente diverse sorgenti di pacchetti (sorgenti remote FTP e HTTP, cdrom, DVD e hard disk), di gestire autonomamente diverse distribuzioni di pacchetti e di permettere velocemente l’aggiornamento del sistema operativo ad una particolare distribuzione. Sotto Debian si hanno tre differenti distribuzioni utilizzabili: stable, testing e unstable. Attualmente la stable di Debian è la etch mentre la testing (cioè la prossima versione designata per diventare stable) è la Lenny; infine conosciuta da tutti e sempre con lo stesso nome c’è la unstable che va sotto il nome di SID.
Inutile premettere che l’uso di APT è valido per tutte quelle distro figlie di debian come Ubuntu e per tutte quelle che adottano tale gestore per pacchettizzare i vari software software.
Innanzitutto dobbiamo procurarci un elenco di repository (archivio dove sono raccolti i pacchetti Debian [siano essi pacchetti binari o sorgenti] in modo ben organizzato e costantemente aggiornato).
Tali repository devono essere salvati nel file /etc/apt/sources.list.
A questo punto…..
apt-get update (serve per far riconoscere le modifiche ad apt)
apt-get install NOME PACCHETTO (comando per installate il pacchetto voluto]
apt-get remove NOME PACCHETTO (disinstalla il pacchetto)
apt-get –purge remove NOME PACCHETTO (con l’aggiunta di PURGE non ci si limita a disinstallare solo il pacchetto ma bensì tutti i file di configurazione—consigliato per una pulizia approfondita del sistema)
apt-get upgrade (controlla e aggiorna tutti i pacchetti installati)Con questi comandi avrete aggiornato il vostro sistema, installerete e disinstallerete qualsia programma vogliate provare

Apt però ha molte funzioni utili che vi consiglio di provare….
apt-get –simulate AZIONE ( serve per simulare un azione per vedere come realmente si comporta il sistema. Molto utile quando si vuole fare un upgrade es. apt-get -simulate upgrade vi simulerà un upgrade dell’intero sistema, se tutto andrà ok allora potrete realmente passare ai fatti)

Volete installare un software ma non ricordate il nome?
Usate: apt-cache search NOME PACCHETTO
Oppure apt-cache search NOME PACCHETTO APPROSSIMATIVO (attenzione vi rilasci era una lista di programmi che contengono le lettere che avete inserito nella ricerca)
Per meglio cercare il pacchetto usate apt-cache search ^NOME APPROSSIMATIVO PACCHETTO (agiungendo ^ vi segnalerà solo i pacchetti che iniziano per quelle lettere es ^pip vi rilascerà pippo pippolo ecc ma mai hipippo)

Concludo con una chicca che mi capita raramente di trovare nelle guide è l’uso di DPKG. Questo comando è utile in caso di ripristino di una macchina con la possibilità di ritrovarci i medesimi programmi usati prima della formattazione.
I passi sono semplici con:

dpkg -get-selection (legge il software installato e lo mostra in video)
dpkg -get-selection > pippo (salverà l’elenco in un file di nome pippo)
A questo punto dopo aver creato il file nell’eventualità che vogliate piallare tutto potreste tranquillamente tramite i comandi che vi riporterò sotto, riportare il nuovo sistema alla situazione precedente la formattazione; basta usare in sequenza:
dpkg -set-selection (Questo comando imposterà la selezione del software ma non lo installa)
dpkg -set-selection < pippo

apt-get dselect-upgrade (il gioco è fatto riavrete tutti i programmi che avevate installato sul precedente sistema)

alternatives

per configurare le alternatives:

<code>sudo update-alternatives --config java</code>

al menu scegliamo la nostra preferenza <code></code>

se vogliamo aggiungere una possibilità

<code>sudo update-alternatives --install /usr/bin/java java /opt/jdk1.5.0_12/java 30</code>