{"id":12355,"date":"2019-03-26T21:18:15","date_gmt":"2019-03-26T21:18:15","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12355"},"modified":"2019-03-26T21:18:15","modified_gmt":"2019-03-26T21:18:15","slug":"understanding-apt-apt-cache-and-their-frequently-used-commands","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/understanding-apt-apt-cache-and-their-frequently-used-commands\/","title":{"rendered":"Understanding APT, APT-Cache and Their Frequently Used Commands"},"content":{"rendered":"<p>If you\u2019ve ever used\u00a0<strong>Debian<\/strong>\u00a0or a\u00a0<strong>Debian<\/strong>\u00a0based distribution like\u00a0<strong>Ubuntu<\/strong>\u00a0or\u00a0<strong>Linux Mint<\/strong>, then chances are that you\u2019ve used the\u00a0<strong>APT<\/strong>\u00a0package system to\u00a0<strong>install<\/strong>\u00a0or\u00a0<strong>remove<\/strong>\u00a0software. Even if you\u2019ve never dabbled on the command line, the underlying system that powers your package manager\u00a0<strong>GUI<\/strong>\u00a0is the\u00a0<strong>APT<\/strong>\u00a0system.<\/p>\n<div id=\"attachment_4643\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/11\/apt-get-and-apt-cache-commands.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4643\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/11\/apt-get-and-apt-cache-commands.png\" alt=\"apt-get commands and apt-cache commands\" width=\"442\" height=\"317\" aria-describedby=\"caption-attachment-4643\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-4643\" class=\"wp-caption-text\">Understanding APT and APT-Cache<\/p>\n<\/div>\n<p>Today, we are going to take a look at some familiar commands, and dive into some less or more frequently used\u00a0<strong>APT<\/strong>\u00a0commands, and shed some light on this brilliantly designed system.<\/p>\n<h3>What is APT?<\/h3>\n<p><strong>APT<\/strong>\u00a0stands for\u00a0<strong>Advanced Package Tool<\/strong>. It was first seen in\u00a0<strong>Debian 2.1<\/strong>\u00a0back in\u00a0<strong>1999<\/strong>. Essentially,\u00a0<strong>APT<\/strong>\u00a0is a management system for\u00a0<a href=\"https:\/\/www.tecmint.com\/dpkg-command-examples\/\" target=\"_blank\" rel=\"noopener\">dpkg packages<\/a>, as seen with the extension\u00a0<strong>*.deb<\/strong>. It was designed to not only\u00a0<strong>manage packages<\/strong>\u00a0and\u00a0<strong>updates<\/strong>, but to solve the many\u00a0<strong>dependency issues<\/strong>\u00a0when installing certain packages.<\/p>\n<p>As anyone who was using\u00a0<strong>Linux<\/strong>\u00a0back in those pioneer days, we were all too familiar with the term \u201c<strong>dependency hell<\/strong>\u201d when trying to compile something from source, or even when dealing with a number of\u00a0<strong>Red Hat<\/strong>\u2019s individual\u00a0<a href=\"https:\/\/www.tecmint.com\/20-practical-examples-of-rpm-commands-in-linux\/\" target=\"_blank\" rel=\"noopener\">RPM files<\/a>.<\/p>\n<p><strong>APT<\/strong>\u00a0solved all of these dependency issues automatically, making installing any package, regardless of the size or number of dependencies a one line command. To those of us who laboured for hours on these tasks, this was one of those \u201c<strong>sun parting the clouds<\/strong>\u201d moments in our\u00a0<strong>Linux lives<\/strong>!<\/p>\n<h3>Understanding APT Configuration<\/h3>\n<p>This first file we are going to look at is one of\u00a0<strong>APT\u2019<\/strong>s configuration files.<\/p>\n<pre>$ sudo cat \/etc\/apt\/sources.list<\/pre>\n<h5>Sample Output<\/h5>\n<pre>deb http:\/\/us-west-2.ec2.archive.ubuntu.com\/ubuntu\/ precise main\r\ndeb-src http:\/\/us-west-2.ec2.archive.ubuntu.com\/ubuntu\/ precise main\r\n\r\ndeb http:\/\/us-west-2.ec2.archive.ubuntu.com\/ubuntu\/ precise-updates main\r\ndeb-src http:\/\/us-west-2.ec2.archive.ubuntu.com\/ubuntu\/ precise-updates main\r\n\r\ndeb http:\/\/us-west-2.ec2.archive.ubuntu.com\/ubuntu\/ precise universe\r\ndeb-src http:\/\/us-west-2.ec2.archive.ubuntu.com\/ubuntu\/ precise universe\r\ndeb http:\/\/us-west-2.ec2.archive.ubuntu.com\/ubuntu\/ precise-updates universe\r\ndeb-src http:\/\/us-west-2.ec2.archive.ubuntu.com\/ubuntu\/ precise-updates universe\r\n\r\ndeb http:\/\/security.ubuntu.com\/ubuntu precise-security main\r\ndeb-src http:\/\/security.ubuntu.com\/ubuntu precise-security main\r\ndeb http:\/\/security.ubuntu.com\/ubuntu precise-security universe\r\ndeb-src http:\/\/security.ubuntu.com\/ubuntu precise-security universe<\/pre>\n<p>As you can probably deduce from my\u00a0<strong>sources.list<\/strong>\u00a0file, I\u2019m using\u00a0<strong>Ubuntu 12.04<\/strong>\u00a0(<strong>Precise Pangolin<\/strong>). I\u2019m also using three repositories:<\/p>\n<ol>\n<li>Main Repository<\/li>\n<li>Universe Repository<\/li>\n<li>Ubuntu Security Repository<\/li>\n<\/ol>\n<p>The syntax of this file is relatively simple:<\/p>\n<pre>deb (url) release repository<\/pre>\n<p>The accompanying line is the source file repository. It follows a similar format:<\/p>\n<pre>deb-src (url) release repository<\/pre>\n<p>This file is pretty much the only thing you\u2019ll ever have to edit using\u00a0<strong>APT<\/strong>, and chances are that the defaults will server you quite well and you will never need to edit it at all.<\/p>\n<p>However, there are times that you might want to\u00a0<strong>add third-party<\/strong>\u00a0repositories. You would simple enter them using the same format, and then run the\u00a0<strong>update<\/strong>\u00a0command:<\/p>\n<pre>$ sudo apt-get update<\/pre>\n<p><strong>NOTE<\/strong>: Be very mindful of\u00a0<strong>adding third party<\/strong>\u00a0repositories!!! Only add from\u00a0<strong>trusted<\/strong>\u00a0and\u00a0<strong>reputable sources<\/strong>. Adding dodgy repositories or mixing releases can seriously mess up your system!<\/p>\n<p>We\u2019ve taken a look at our\u00a0<strong>sources.list<\/strong>\u00a0file and now know how to update it, so what\u2019s next? Let\u2019s install some packages. Let\u2019s say that we are running a server and we want to install\u00a0<strong>WordPress<\/strong>. First let\u2019s search for the package:<\/p>\n<pre>$ sudo apt-cache search wordpress<\/pre>\n<h5>Sample Output<\/h5>\n<pre>blogilo - graphical blogging client\r\ndrivel - Blogging client for the GNOME desktop\r\ndrupal6-mod-views - views modules for Drupal 6\r\ndrupal6-thm-arthemia - arthemia theme for Drupal 6\r\ngnome-blog - GNOME application to post to weblog entries\r\nlekhonee-gnome - desktop client for wordpress blogs\r\nlibmarkdown-php - PHP library for rendering Markdown data\r\nqtm - Web-log interface program\r\ntomboy-blogposter - Tomboy add-in for posting notes to a blog\r\nwordpress - weblog manager\r\nwordpress-l10n - weblog manager - language files\r\nwordpress-openid - OpenID plugin for WordPress\r\nwordpress-shibboleth - Shibboleth plugin for WordPress\r\nwordpress-xrds-simple - XRDS-Simple plugin for WordPress\r\nzine - Python powered blog engine<\/pre>\n<h3>What is APT-Cache?<\/h3>\n<p><strong>Apt-cache<\/strong>\u00a0is a command that simply queries the\u00a0<strong>APT<\/strong>\u00a0cache. We passed the search parameter to it, stating that, obviously, we want to search\u00a0<strong>APT<\/strong>\u00a0for it. As we can see above, searching for \u201c<strong>wordpress<\/strong>\u201d returned a number of packages that related to the search string with a short description of each package.<\/p>\n<p>From this, we see the main package of \u201c<strong>wordpress \u2013 weblog manager<\/strong>,\u201d and we want to install it. But wouldn\u2019t it be nice to see exactly what dependencies are going to be installed along with it?\u00a0<strong>APT<\/strong>\u00a0can tell us that as well:<\/p>\n<pre>$ sudo apt-cache showpkg wordpress<\/pre>\n<h5>Sample Output<\/h5>\n<pre>Versions:\r\n3.3.1+dfsg-1 (\/var\/lib\/apt\/lists\/us-west-2.ec2.archive.ubuntu.com_ubuntu_dists_precise_universe_binary-amd64_Packages)\r\n Description Language:\r\n                 File: \/var\/lib\/apt\/lists\/us-west-2.ec2.archive.ubuntu.com_ubuntu_dists_precise_universe_binary-amd64_Packages\r\n                  MD5: 3558d680fa97c6a3f32c5c5e9f4a182a\r\n Description Language: en\r\n                 File: \/var\/lib\/apt\/lists\/us-west-2.ec2.archive.ubuntu.com_ubuntu_dists_precise_universe_i18n_Translation-en\r\n                  MD5: 3558d680fa97c6a3f32c5c5e9f4a182a\r\n\r\nReverse Depends:\r\n  wordpress-xrds-simple,wordpress\r\n  wordpress-shibboleth,wordpress 2.8\r\n  wordpress-openid,wordpress\r\n  wordpress-l10n,wordpress 2.8.4-2\r\nDependencies:\r\n3.3.1+dfsg-1 - libjs-cropper (2 1.2.1) libjs-prototype (2 1.7.0) libjs-scriptaculous (2 1.9.0) libphp-phpmailer (2 5.1) libphp-simplepie (2 1.2) libphp-snoopy (2 1.2.4) tinymce (2 3.4.3.2+dfsg0) apache2 (16 (null)) httpd (0 (null)) mysql-client (0 (null)) libapache2-mod-php5 (16 (null)) php5 (0 (null)) php5-mysql (0 (null)) php5-gd (0 (null)) mysql-server (2 5.0.15) wordpress-l10n (0 (null))\r\nProvides:\r\n3.3.1+dfsg-1 -\r\nReverse Provides:<\/pre>\n<p>This shows us that\u00a0<strong>wordpress 3.3.1<\/strong>\u00a0is the version to be installed, the repository it is to be installed from, reverse dependencies, and other packages it depends on, plus their version numbers.<\/p>\n<p><strong>NOTE<\/strong>: (<strong>null<\/strong>\u00a0means that the version is not defined, and the latest version in the repository will be installed.)<\/p>\n<p>Now, the actual install command:<\/p>\n<pre>$ sudo apt-get install wordpress<\/pre>\n<p>That command will install\u00a0<strong>WordPress-3.3.1<\/strong>\u00a0and all dependencies that are not currently installed.<\/p>\n<p>Of course, that is not all you can do with\u00a0<strong>APT<\/strong>. Some other useful commands are as follow:<\/p>\n<p><strong>NOTE<\/strong>: It is a good practice to run\u00a0<strong>apt-get update<\/strong>\u00a0before running any series of\u00a0<strong>APT<\/strong>\u00a0commands. Remember,\u00a0<strong>apt-get update<\/strong>\u00a0parses your\u00a0<strong>\/etc\/apt\/sources.list<\/strong>\u00a0file and updates its database.<\/p>\n<p>Uninstalling a package is just as easy as installing the package:<\/p>\n<pre>$ sudo apt-get remove wordpress<\/pre>\n<p>Unfortunately, the\u00a0<strong>apt-get remove<\/strong>\u00a0command leave all of the configuration files intact. To remove those as well, you\u2019ll want to use\u00a0<strong>apt-get purge<\/strong>:<\/p>\n<pre>$ sudo apt-get purge wordpress<\/pre>\n<p>Every now and then, you might run across a situation where there are broken dependencies. This usually happens when you don\u2019t run\u00a0<strong>apt-get update<\/strong>\u00a0properly, mangling the database. Fortunately,\u00a0<strong>APT<\/strong>\u00a0has a fix for it:<\/p>\n<pre>$ sudo apt-get \u2013f install<\/pre>\n<p>Since\u00a0<strong>APT<\/strong>\u00a0downloads all of the\u00a0<strong>*.deb<\/strong>\u00a0files from the repository right to your machine (stores them in<strong>\/var\/cache\/apt\/archives<\/strong>) you might want to periodically remove them to free up disk space:<\/p>\n<pre>$ sudo apt-get clean<\/pre>\n<p>This is just a small fraction of\u00a0<strong>APT<\/strong>,\u00a0<strong>APT-Cache<\/strong>\u00a0and some of its useful commands. There are still lot to learn and explore some more advanced commands at below article.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management\/\" target=\"_blank\" rel=\"noopener\">25 Useful and Advanced Commands of APT-GET and APT-CACHE<\/a><\/li>\n<\/ol>\n<p>As always, please have a look at the man pages for even more options. Once one gains a familiarity with\u00a0<strong>APT<\/strong>, it is possible to write awesome Cron scripts to keep the system up to date.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/apt-get-and-apt-cache-and-their-frequently-used-commands\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019ve ever used\u00a0Debian\u00a0or a\u00a0Debian\u00a0based distribution like\u00a0Ubuntu\u00a0or\u00a0Linux Mint, then chances are that you\u2019ve used the\u00a0APT\u00a0package system to\u00a0install\u00a0or\u00a0remove\u00a0software. Even if you\u2019ve never dabbled on the command line, the underlying system that powers your package manager\u00a0GUI\u00a0is the\u00a0APT\u00a0system. Understanding APT and APT-Cache Today, we are going to take a look at some familiar commands, and dive into some &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/understanding-apt-apt-cache-and-their-frequently-used-commands\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Understanding APT, APT-Cache and Their Frequently Used Commands&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12355","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12355"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12355\/revisions"}],"predecessor-version":[{"id":12356,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12355\/revisions\/12356"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}