Arctus Blog: Linux: the brilliance of APT tag:blog.arctus.co.uk,2005:Typo Typo 2007-05-09T08:39:01-04:00 Adrian O'Connor adrian@arctus.co.uk urn:uuid:17632749-422b-41fe-aed3-8b6a642819ac 2007-05-09T07:58:00-04:00 2007-05-09T08:39:01-04:00 Linux: the brilliance of APT <p><span class="caps">APT</span> is a wonderful tool that is a key part of Debian Linux systems (in particular, the ever popilar Ubuntu).</p> <p>I shall explain here what apt is and what it does because I think that it deserves to be known and understood &#8211; even by people who might never use it. It is a good concept and it makes life much easier for those who know it.</p> <p>Apt is a system designed to automatically download and install pre-packaged software. Its name is an acronym that means Advanced Packaging Tool.</p> <p>There are graphical interfaces for apt, but it is equally usable from the command line. This is my preferred way of controlling apt, but it is especially useful in the management of remote servers. It allows us to take a blank server, anywhere on the internet, and very quickly install all required services and tools using nothing more than a remote shell (like putty). You can easily go from fresh-install to configured application server in under 5 minutes.</p> <p>Apt works from a list of source repositories. These are just web servers that contain data arranged in a particular manner. The servers are listed in a configuration file: /etc/apt/sources.list</p> <p>One of the first things that most Ubuntu users will do is edit this file to remove the # symbol that disables certain &#8216;universe&#8217; repositories [<a href="http://ubuntuguide.org/wiki/Ubuntu:Feisty/Repositories">how</a>]. These universe repositories contain many gigabytes covering the full realm of open source software.</p> <h3>Examples of apt in use</h3> <p>Apt needs to be run with special privileges, and this requires sudo. To make sure that your list of available applications is up to date, you would run:</p> <pre>sudo apt-get update</pre> <p>To get a list of available packages, you can run:</p> <pre>apt-cache pkgnames</pre> <p>That list isn&#8217;t especially useful because it is so long. If you want to search for a keyword (e.g. mysql) you can use the grep command:</p> <pre>apt-cache pkgnames | grep mysql</pre> <p>Apt-cache also supports regular expressions for searching of packages, but grep often works well enough.</p> <h3>A quick example</h3> <p>When I commission a new Ubuntu server I will typically install several packages straight away. For example, these three packages I install on all servers:</p> <pre>sudo apt-get install ssh vim subversion</pre> <p>I then choose from apache2, mysql-server, ruby and several other regulars depending on the requirements for that server.</p> <pre>sudo apt-get install apache2 mysql-server ruby</pre> <p>The only install task that apt doesn&#8217;t currently handle well is the install of rubygems. For this, I always download the latest version from rubyforge and install it manually. Installation and use of rubygems also requires sudo, otherwise it just throws cryptic errors.</p> <h3>The icing on the cake</h3> <p>A recent upgrade of XP to Vista on my laptop took 4 hours to complete (the subsequent format and downgrade took a similar amount of time).</p> <p>One of Ubuntu&#8217;s strengths is the ease with which you can upgrade the entire system. Some prefer the graphical tool for this task, but it is quite possible to use apt. You simply need to change the sources.list file to point at the new version of ubuntu on the servers, and run</p> <pre>sudo apt-get distupgrade</pre> <p>Typically, this will require 300MB of data to be fetched from the remote servers, and on a typical broadband connection will take around an hour. You can use the CD instead, if you prefer. However, once the files are available, it is a super-fast process that is hard to fault. It is a process that is beyond Microsoft&#8217;s wildest dreams, though I am positive that they would very much like to sell you a &#8216;web-upgrade&#8217; to Vista if they could.</p> <p>Apt also handles security updates. These are very simply a matter of running:</p> <pre> sudo apt-get update sudo apt-get upgrade </pre> <p>Again, very fast, very reliable, very much better than Microsoft&#8217;s Windows Update. It&#8217;s also worth noting that it very rarely needs to reboot after applying updates.</p> <h3>Summary</h3> <p>Apt-get is a wonderful tool that makes administration of servers a breeze. I think that as previously Windows Server-only adminstrators start to look at systems like Ubuntu, it is well designed tools like apt that will gradually win them over.</p>