Linux dpkg Command Tutorial voor Beginners (8 Voorbeelden)
Als je op een Debian of op Debian gebaseerd systeem (zoals Ubuntu) werkt, is de kans groot dat je .deb pakketten tegengekomen bent. Dit zijn Debian pakketten, en de Linux commando-regel biedt ingebouwde commando’s/hulpmiddelen om met dit soort pakketten om te gaan. Eén zo’n hulpmiddel is dpkg, dat we hier in deze handleiding zullen bespreken.
Maar voor we dat doen, is het de moeite waard te vermelden dat alle voorbeelden in deze handleiding getest zijn op een Ubuntu 16.04LTS machine.
Linux dpkg commando
Het gereedschap dpkg is in principe een pakketbeheerder voor Debian/Debian-gebaseerde systemen. Hieronder volgt de syntaxis:
dpkg ACTIONS
OR
dpkg [options] filename
En hier is hoe de man pagina het uitlegt:
dpkg is a tool to install, build, remove and manage Debian packages.
The primary and more user-friendly front-end for dpkg is aptitude(1).
dpkg itself is controlled entirely via command line parameters, which
consist of exactly one action and zero or more options. The action-
parameter tells dpkg what to do and options control the behavior of the
action in some way.
dpkg can also be used as a front-end to dpkg-deb(1) and dpkg-query(1).
The list of supported actions can be found later on in the ACTIONS sec?
tion. If any such action is encountered dpkg just runs dpkg-deb or
dpkg-query with the parameters given to it, but no specific options are
currently passed to them, to use any such option the back-ends need to
be called directly.
Hieronder volgen enkele voorbeelden in vraag en antwoord stijl die je een goed basisidee moeten geven over hoe dpkg werkt.
Q1. Hoe installeer je een pakket met dpkg?
Dit kun je doen met de -i commandoregeloptie.
dpkg -i [package-name]
Bijvoorbeeld:
dpkg -i google-chrome-stable_current_amd64.deb
Hier zie je wat alle stappen zijn die bij het installatieproces komen kijken:
1. Extract the control files of the new package.
2. If another version of the same package was installed before
the new installation, execute prerm script of the old package.
3. Run preinst script, if provided by the package.
4. Unpack the new files, and at the same time back up the old
files, so that if something goes wrong, they can be restored.
5. If another version of the same package was installed before
the new installation, execute the postrm script of the old pack?
age. Note that this script is executed after the preinst script
of the new package, because new files are written at the same
time old files are removed.
6. Configure the package. See --configure for detailed informa?
tion about how this is done.
Q2. Hoe verwijder je een reeds geïnstalleerd pakket met dpkg?
Dit kun je doen met de -r commandolijnoptie.
dpkg -r [package-name]
Bijvoorbeeld:
dpkg -r googler_3.3.0-1_all.deb
Hier is wat de man page over deze optie zegt:
Removing of a package consists of the following steps:
1. Run prerm script
2. Remove the installed files
3. Run postrm script
Q3. Hoe maak je een lijst van alle geïnstalleerde pakketten in het systeem?
Hiervoor kun je de -l commandolijn optie gebruiken.
dpkg -l
Hier is bijvoorbeeld de uitvoer die deze commandoregeloptie op mijn systeem opleverde:
Q4. Hoe kan je dpkg een lijst laten maken van de inhoud van een pakket?
Dit kan met de –contents vlag.
dpkg --contents [package name]
Bijvoorbeeld:
Q5. Hoe pak je met dpkg alleen een pakket uit?
Er kunnen momenten zijn waarop je het pakket alleen wilt uitpakken, en niet configureren. Welnu, dpkg biedt ook hiervoor een optie: –unpack.
dpkg --unpack [package-name]
Als je later een al uitgepakt pakket wilt configureren, kun je dat doen met de commandoregeloptie –configure.
dpkg --configure [package-name]
Hieronder staat wat de man page over deze optie zegt:
Configuring consists of the following steps:
1. Unpack the conffiles, and at the same time back up the old
conffiles, so that they can be restored if something goes wrong.
2. Run postinst script, if provided by the package.
Q6. Hoe controleer je of een pakket geïnstalleerd is of niet?
Gebruik hiervoor de -s commandolijnoptie.
dpkg -s [package-name]
Bijvoorbeeld:
Q7. Hoe druk je de architectuur af van pakketten die dpkg installeert?
Deze info is te verkrijgen met de –print-architecture commandolijn optie.
dpkg --print-architecture
De uitvoer die het bovenstaande commando op mijn systeem opleverde was bijvoorbeeld:
amd64
Q8. Hoe een pakket te zuiveren met dpkg?
We bespraken al hoe je een pakket verwijdert met het dpkg commando. Je kunt ook een pakket purgen, een proces dat alles verwijdert, inclusief conffiles. Dit kan met de -P commandolijn optie.
dpkg -P [package-name]
Hier is wat de man pagina over deze optie te zeggen heeft:
Some configuration files might be unknown to dpkg because
they are created and handled separately through the configura?
tion scripts. In that case, dpkg won't remove them by itself,
but the package's postrm script (which is called by dpkg), has
to take care of their removal during purge. Of course, this only
applies to files in system directories, not configuration files
written to individual users' home directories.
Purging of a package consists of the following steps:
1. Remove the package, if not already removed. See --remove for
detailed information about how this is done.
2. Run postrm script.
Conclusie
Het dpkg commando biedt een overvloed aan opties. Wat we hier besproken hebben zijn die opties die je helpen om met het gereedschap aan de slag te gaan. Als je klaar bent met deze te oefenen, ga dan naar deman pagina van het commando voor meer informatie.