{"id":5181,"date":"2018-06-28T21:23:46","date_gmt":"2018-06-28T17:23:46","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-dpkg-command\/"},"modified":"2018-06-28T21:23:46","modified_gmt":"2018-06-28T17:23:46","slug":"linux-dpkg-command-tutorial-for-beginners-8-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-dpkg-command-tutorial-for-beginners-8-examples\/","title":{"rendered":"Linux dpkg Command Tutorial for Beginners (8 Examples)"},"content":{"rendered":"<p>If you are on a Debian or Debian-based system (like Ubuntu), there are high chances you might have encountered .deb packages. These are Debian packages, and Linux command line offers built-in commands\/tools to deal with this kind of packages. One such tool is <strong>dpkg<\/strong>, which we will discuss here in this tutorial.<\/p>\n<p>But before we do that, it&#8217;s worth mentioning that all examples in this tutorial have been tested on an Ubuntu 16.04LTS machine.<\/p>\n<h2 id=\"linux-dpkg-command\">Linux dpkg command<\/h2>\n<p>The dpkg tool is basically a package manager for Debian\/Debian-based systems. Following is its syntax:<\/p>\n<p class=\"command\">dpkg ACTIONS<\/p>\n<p>OR<\/p>\n<p class=\"command\">dpkg [options] filename<\/p>\n<p>And here&#8217;s how the man page explains it:<\/p>\n<pre readability=\"10\"> dpkg\u00a0 is\u00a0 a\u00a0 tool to install, build, remove and manage Debian packages.<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The primary and more user-friendly front-end for dpkg\u00a0 is\u00a0 aptitude(1).<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 dpkg\u00a0 itself\u00a0 is controlled entirely via command line parameters, which<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 consist of exactly one action and zero or\u00a0 more\u00a0 options.\u00a0 The\u00a0 action-<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 parameter tells dpkg what to do and options control the behavior of the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 action in some way.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 dpkg can also be used as a front-end to dpkg-deb(1) and\u00a0 dpkg-query(1).<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The list of supported actions can be found later on in the ACTIONS sec?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tion. If any such action is encountered\u00a0 dpkg\u00a0 just\u00a0 runs\u00a0 dpkg-deb\u00a0 or<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 dpkg-query with the parameters given to it, but no specific options are<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 currently passed to them, to use any such option the back-ends need\u00a0 to<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 be called directly.<\/p><\/pre>\n<p>Following are some Q&amp;A styled examples that should give you a good basic idea on how dpkg works.<\/p>\n<h2 id=\"q-how-to-install-a-package-using-dpkg\">Q1. How to install a package using dpkg?<\/h2>\n<p>This you can do using the -i command line option.<\/p>\n<p class=\"command\">dpkg -i [package-name]\n<p>For example:<\/p>\n<p class=\"command\">dpkg -i google-chrome-stable_current_amd64.deb<\/p>\n<p>Here&#8217;s what all steps are involved in the installation process:<\/p>\n<pre readability=\"26\"><br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1. Extract the control files of the new package.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2.\u00a0 If\u00a0 another version of the same package was installed before<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 the new installation, execute prerm script of the old package.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3. Run preinst script, if provided by the package.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4. Unpack the new files, and at the same time back\u00a0 up\u00a0 the\u00a0 old<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 files, so that if something goes wrong, they can be restored.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 5.\u00a0 If\u00a0 another version of the same package was installed before<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 the new installation, execute the postrm script of the old pack?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 age.\u00a0 Note that this script is executed after the preinst script<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 of the new package, because new files are written\u00a0 at\u00a0 the\u00a0 same<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 time old files are removed.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 6.\u00a0 Configure the package. See --configure for detailed informa?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tion about how this is done.<\/p><\/pre>\n<h2 id=\"q-how-to-remove-an-already-installed-package-using-dpkg\">Q2. How to remove an already installed package using dpkg?<\/h2>\n<p>This can be done using the -r command line option.<\/p>\n<p class=\"command\">dpkg -r [package-name]\n<p>For example:<\/p>\n<p class=\"command\">dpkg -r googler_3.3.0-1_all.deb<\/p>\n<p>Here&#8217;s what the man page says about this option:<\/p>\n<pre readability=\"9\"> Removing of a package consists of the following steps:<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1. Run prerm script<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2. Remove the installed files<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3. Run postrm script<\/p><\/pre>\n<h2 id=\"q-how-to-list-all-installed-packages-in-the-system\">Q3. How to list all installed packages in the system?<\/h2>\n<p>For this, you can use the -l command line option.<\/p>\n<p class=\"command\">dpkg -l<\/p>\n<p>For example, here&#8217;s the output this command line option produced on my system:<\/p>\n<p><a class=\"fancybox\" id=\"img-dpkg-l-output\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/dpkg-l-output.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-dpkg-command-tutorial-for-beginners-8-examples.png\" alt=\"How to list all installed packages in the system\" width=\"550\" height=\"296\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-dpkg-list-contents-of-a-package\">Q4. How to make dpkg list contents of a package?<\/h2>\n<p>This can be done using the &#8211;contents flag.<\/p>\n<p class=\"command\">dpkg &#8211;contents [package name]\n<p>For example:<\/p>\n<p><a class=\"fancybox\" id=\"img-dpkg-contents-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/dpkg-contents-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-dpkg-command-tutorial-for-beginners-8-examples-1.png\" alt=\"How to make dpkg list contents of a package\" width=\"550\" height=\"146\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-just-unpack-a-package-using-dpkg\">Q5. How to just unpack a package using dpkg?<\/h2>\n<p>There may be times when you&#8217;d want to just unpack the package, not configure it. Well, dpkg provides an option for this as well: &#8211;unpack.<\/p>\n<p class=\"command\">dpkg &#8211;unpack [package-name]\n<p>If later on you&#8217;d like to configure an already unpacked package, you can do so using the &#8211;configure command line option.<\/p>\n<p class=\"command\">dpkg &#8211;configure [package-name]\n<p>Following is what the man page says about this option:<\/p>\n<pre readability=\"11\"> Configuring consists of the following steps:<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.\u00a0 Unpack\u00a0 the\u00a0 conffiles, and at the same time back up the old<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 conffiles, so that they can be restored if something goes wrong.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2. Run postinst script, if provided by the package.<\/p><\/pre>\n<h2 id=\"q-how-to-check-if-a-package-is-installed-or-not\">Q6. How to check if a package is installed or not?<\/h2>\n<p>Use the -s command line option for this.<\/p>\n<p class=\"command\">dpkg -s [package-name]\n<p>For example:<\/p>\n<p><a class=\"fancybox\" id=\"img-dpkg-s-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/dpkg-s-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-dpkg-command-tutorial-for-beginners-8-examples-2.png\" alt=\"How to check if a .deb package is installed or not\" width=\"500\" height=\"39\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-print-architecture-of-packages-dpkg-installs\">Q7. How to print architecture of packages dpkg installs?<\/h2>\n<p>This info can be accessed using the &#8211;print-architecture command line option.<\/p>\n<p class=\"command\">dpkg &#8211;print-architecture<\/p>\n<p>For example, the output the above command produced on my system was:<\/p>\n<pre>amd64<\/pre>\n<h2 id=\"q-how-to-purge-a-package-using-dpkg\">Q8. How to purge a package using dpkg?<\/h2>\n<p>We already discussed how to remove a package using the dpkg command. You can also purge a package, a process which removes everything, including conffiles. This can be done using the -P command line option.<\/p>\n<p class=\"command\">dpkg -P [package-name]\n<p>Here&#8217;s what the man page has to say about this option:<\/p>\n<pre readability=\"11\"> Some configuration files might be unknown to dpkg because<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 they are created and handled separately through\u00a0 the\u00a0 configura?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tion\u00a0 scripts.\u00a0 In\u00a0 that case, dpkg won't remove them by itself,<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 but the package's postrm script (which is called by\u00a0 dpkg),\u00a0 has<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 to take care of their removal during purge. Of course, this only<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 applies to files in system directories, not configuration\u00a0 files<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 written to individual users' home directories.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Purging of a package consists of the following steps:<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.\u00a0 Remove the package, if not already removed. See --remove for<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 detailed information about how this is done.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2. Run postrm script.<\/p><\/pre>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>The dpkg command offers plethora of options. What we&#8217;ve discussed here are those options that will help you get started with the tool. Once you&#8217;re done practicing these, head to the command&#8217;s\u00a0<a href=\"https:\/\/linux.die.net\/man\/1\/dpkg\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a> for more information.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-dpkg-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-dpkg-command-tutorial-for-beginners-8-examples-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-dpkg-command%2F&amp;text=Linux+dpkg+Command+Tutorial+for+Beginners+%288+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-dpkg-command-tutorial-for-beginners-8-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-dpkg-command-tutorial-for-beginners-8-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-dpkg-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-dpkg-command-tutorial-for-beginners-8-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you are on a Debian or Debian-based system (like Ubuntu), there are high chances you might have encountered .deb packages. These are Debian packages, and Linux command line offers built-in commands\/tools to deal with this kind of packages. One such tool is dpkg, which we will discuss here in this tutorial. But before we &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-5181","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=5181"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5181\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=5181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=5181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=5181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}