list_installed_packages_on_debian.html 9.3 KB

123456789101112131415161718192021222324252627
  1. <!DOCTYPE html><html class="no-js" lang="en-us"><head><meta charset="utf-8"/>
  2. <head>
  3. <title>How to list installed packages on Debian</title>
  4. <body>
  5. <h1>How to list installed packages on Debian</h1>
  6. <p>In this guide, we’ll explain how to list and filter installed packages on Debian. We will also show you how to check whether a specific package is installed, count installed packages and find out the version of an installed package.</p><p>Knowing how to list installed packages on your Debian based system can be helpful in situations where you need to install the same packages on another machine or if you want to re-install your system.<span id="ezoic-pub-ad-placeholder-158" class="ezoic-adpicker-ad"></span></p><h2 id="list-installed-packages-with-apt">List Installed Packages with Apt <a class="headline-link" href="#list-installed-packages-with-apt" aria-hidden="true">#</a></h2><p><a href="https://wiki.debian.org/Apt" target="_blank" rel="noopener">Apt</a>
  7. is a command-line interface for the package management system and combines the most commonly used functionalities from <code>apt-get</code> and <code>apt-cache</code> including an option to list installed packages.<span id="ezoic-pub-ad-placeholder-138" class="ezoic-adpicker-ad"></span></p><p>To lists all packages installed on your system run the following command:</p><pre class="terminal"><code class="terminal-line" prefix="$">sudo apt list --installed</code></pre><pre><code class="language-output" data-lang="output">adduser/stable,now 3.115 all [installed]
  8. apt/stable,now 1.4.8 amd64 [installed]
  9. apt-listchanges/stable,now 3.10 all [installed]
  10. apt-utils/stable,now 1.4.8 amd64 [installed]
  11. autoconf/stable,now 2.69-10 all [installed]
  12. automake/stable,now 1:1.15-6 all [installed]
  13. autotools-dev/stable,now 20161112.1 all [installed,automatic]
  14. base-files/stable,now 9.9+deb9u5 amd64 [installed]
  15. base-passwd/stable,now 3.5.43 amd64 [installed]
  16. bash/stable,now 4.4-5 amd64 [installed]
  17. </code></pre><p>The command will display a list of all installed packages including information about the packages versions and architecture. The rightmost column in the output shows whether the package was automatically installed as a dependency of another package.<span id="ezoic-pub-ad-placeholder-139" class="ezoic-adpicker-ad"></span><span class='ezoic-ad box-3 box-3139 adtester-container adtester-container-139' data-ez-name='linuxize_com-box-3'><span id='div-gpt-ad-linuxize_com-box-3-0' ezaw='336' ezah='280' style='position:relative;z-index:0;display:inline-block;min-height:280px;min-width:336px;' class='ezoic-ad'><script data-ezscrex='false' data-cfasync='false' type='text/javascript' style='display:none;'>eval(ez_write_tag([[336,280],'linuxize_com-box-3','ezslot_3',139,'0','0']));</script></span></span></p><p>Since the packages list is long it is a good idea to pipe the output to the <code>less</code> command to make it easier to read:<span id="ezoic-pub-ad-placeholder-156" class="ezoic-adpicker-ad"></span><span class='ezoic-ad medrectangle-3 medrectangle-3156 adtester-container adtester-container-156' data-ez-name='linuxize_com-medrectangle-3'><span id='div-gpt-ad-linuxize_com-medrectangle-3-0' ezaw='580' ezah='400' style='position:relative;z-index:0;display:inline-block;min-height:400px;min-width:580px;' class='ezoic-ad'><script data-ezscrex='false' data-cfasync='false' type='text/javascript' style='display:none;'>eval(ez_write_tag([[580,400],'linuxize_com-medrectangle-3','ezslot_1',156,'0','0']));</script></span></span></p><pre class="terminal"><code class="terminal-line" prefix="$">sudo apt list --installed | less</code></pre><p><span id="ezoic-pub-ad-placeholder-159" class="ezoic-adpicker-ad"></span>To find out whether a specific package is installed, use the <a href="https://linuxize.com/post/how-to-use-grep-command-to-search-files-in-linux/">grep command</a>
  18. to filter the output. For example to find whether the <a href="https://linuxize.com/post/getting-started-with-tmux/">tmux</a>
  19. package is installed on the system you would type:<span id="ezoic-pub-ad-placeholder-140" class="ezoic-adpicker-ad"></span></p><pre class="terminal"><code class="terminal-line" prefix="$">sudo apt list --installed | grep tmux</code></pre><pre><code class="language-output" data-lang="output">tmux/stable,now 2.3-4 amd64 [installed]
  20. </code></pre><p>The output above shows that you have tmux 2.3-4 installed on your system.</p><h2 id="list-installed-packages-with-dpkg-query">List Installed Packages with dpkg-query <a class="headline-link" href="#list-installed-packages-with-dpkg-query" aria-hidden="true">#</a></h2><p><code>dpkg-query</code> is a command line that can be used to display information about packages listed in the dpkg database.</p><p>To get a list of all installed packages type:</p><pre class="terminal"><code class="terminal-line" prefix="$">sudo dpkg-query -l | less</code></pre><figure class="relative"><div class="relative block w-full mx-auto my-0"><div class="block" style="padding-bottom:20.150273224043715%"></div><div class="bg-gray-100 absolute inset-0 w-full h-full m-auto overflow-hidden"><img class="ezlazyload absolute inset-0 w-full h-full m-auto" loading="lazy" src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22768%22%20height%3D%22155%22%3E%3C%2Fsvg%3E" alt="List installed packages with dpkg-query" ezimgfmt="rs rscb87 src ng ngcb87" data-ezsrc="/post/how-to-list-installed-packages-on-debian/debian-list-installed-packages-with-dpkg-query_huc8962be8072673a00274b4ac1c3966a5_75736_768x0_resize_q75_lanczos.jpg"/></div></div></figure><p>The command will display a list of all installed packages including the packages versions, architecture, and a short description.</p><p>You can filter the <code>dpkg-query -l</code> output using the <code>grep</code> command:<span id="ezoic-pub-ad-placeholder-142" class="ezoic-adpicker-ad"></span><span class='ezoic-ad medrectangle-4 medrectangle-4142 adtester-container adtester-container-142' data-ez-name='linuxize_com-medrectangle-4'><span id='div-gpt-ad-linuxize_com-medrectangle-4-0' ezaw='580' ezah='400' style='position:relative;z-index:0;display:inline-block;width:100%;max-width:1200px;margin-left:auto !important;margin-right:auto !important;min-height:400px;min-width:580px;' class='ezoic-ad'><script data-ezscrex='false' data-cfasync='false' type='text/javascript' style='display:none;'>eval(ez_write_tag([[580,400],'linuxize_com-medrectangle-4','ezslot_2',142,'0','0']));</script></span></span></p><pre class="terminal"><code class="terminal-line" prefix="$">sudo dpkg-query -l | grep package_name_to_search</code></pre><h2 id="create-a-list-of-all-installed-packages">Create a List of all Installed Packages <a class="headline-link" href="#create-a-list-of-all-installed-packages" aria-hidden="true">#</a></h2><p>The following command will store the list of all installed packages on your Debian system to a file called <code>packages_list.txt</code>:<span id="ezoic-pub-ad-placeholder-160" class="ezoic-adpicker-ad"></span></p><pre class="terminal"><code class="terminal-line" prefix="$">sudo dpkg-query -f &#39;${binary:Package}\n&#39; -W &gt; packages_list.txt</code></pre><p>Now that you have the list, you can install the same packages on your new server with:</p><pre class="terminal"><code class="terminal-line" prefix="$">sudo xargs -a packages_list.txt apt install</code></pre><h2 id="count-the-number-of-installed-packages">Count the Number of Installed Packages <a class="headline-link" href="#count-the-number-of-installed-packages" aria-hidden="true">#</a></h2><p>To find out how many packages are installed on your system you can use the same command as when creating a packages list but instead of redirecting the output to a file you can pipe it to the <code>wc</code> command to count the lines:</p><pre class="terminal"><code class="terminal-line" prefix="$">sudo dpkg-query -f &#39;${binary:Package}\n&#39; -W | wc -l</code></pre><p>The output will show the number of installed packages:<span id="ezoic-pub-ad-placeholder-143" class="ezoic-adpicker-ad"></span><span class='ezoic-ad box-4 box-4143 adtester-container adtester-container-143' data-ez-name='linuxize_com-box-4'><span id='div-gpt-ad-linuxize_com-box-4-0' ezaw='300' ezah='250' style='position:relative;z-index:0;display:inline-block;min-height:250px;min-width:300px;' class='ezoic-ad'><script data-ezscrex='false' data-cfasync='false' type='text/javascript' style='display:none;'>eval(ez_write_tag([[300,250],'linuxize_com-box-4','ezslot_4',143,'0','0']));</script></span></span></p><pre><code class="language-output" data-lang="output">466
  21. </code></pre><h2 id="conclusion">Conclusion <a class="headline-link" href="#conclusion" aria-hidden="true">#</a></h2><p><span id="ezoic-pub-ad-placeholder-161" class="ezoic-adpicker-ad"></span><span class='ezoic-ad banner-1 banner-1161 adtester-container adtester-container-161' data-ez-name='linuxize_com-banner-1'><span id='div-gpt-ad-linuxize_com-banner-1-0' ezaw='728' ezah='90' style='position:relative;z-index:0;display:inline-block;width:100%;max-width:1200px;margin-left:auto !important;margin-right:auto !important;min-height:90px;min-width:728px;' class='ezoic-ad'><script data-ezscrex='false' data-cfasync='false' type='text/javascript' style='display:none;'>eval(ez_write_tag([[728,90],'linuxize_com-banner-1','ezslot_9',161,'0','0']));</script></span></span>In this tutorial, you learned how to list and filter installed packages on your Debian system.</p>
  22. </body></html>