I think ... - apt-gethttps://blog.kmonsoor.com/2016-10-10T00:00:00+06:00Ubuntu - Update APT-GET Server to Use FastestĀ Mirror2016-10-10T00:00:00+06:002016-10-10T00:00:00+06:00Khaled Monsoortag:blog.kmonsoor.com,2016-10-10:/ubuntu-update-apt-get-server-to-use-fastest-mirror/<p>Updating Ubuntu from it&rsquo;s default server takes too damn long. Give it a 10x&nbsp;boost.</p><h2 id="prelude">Prelude<a class="headerlink" href="#prelude" title="Permanent link">&para;</a></h2> <p>By default, Ubuntu sets the update server pointing to its own (<a href="http://archive.ubuntu.com">http://archive.ubuntu.com</a>). It is the safest bet for Ubuntu. But, that&rsquo;s not the case for users, especially who are outside <span class="caps">USA</span>. To make it smoother as well as distribute the load, Ubuntu also provides a list of mirror sites. You can find the official mirror list <a href="https://launchpad.net/ubuntu/+archivemirrors">here</a>. </p> <p>However, it needs some&nbsp;configuration.</p> <h2 id="on-gui">On <span class="caps">GUI</span><a class="headerlink" href="#on-gui" title="Permanent link">&para;</a></h2> <p>Yes, you can do the selection on Ubuntu using its <span class="caps">GUI</span> tool. But, the problem is it don&rsquo;t always work as you&nbsp;want.</p> <blockquote> <p>It works on geolocation, giving me the local server, which is waaaayy slower where I am. The network temporal distance is the important factor here, not spatial distance (<a href="http://askubuntu.com/a/9035/113604">http://askubuntu.com/a/9035/113604</a>)</p> </blockquote> <p><img alt="Ubuntu-select-update-server-GUI" src="http://i.imgur.com/sCWr0zrl.png"></p> <h2 id="so-what-else-do-we-have">so, what else do we have ?<a class="headerlink" href="#so-what-else-do-we-have" title="Permanent link">&para;</a></h2> <p>I use a handy tool for this purpose to point me to the fastest server <span class="caps">FOR</span> <span class="caps">ME</span>. It&rsquo;s <a href="https://github.com/jblakeman/apt-select">apt-select</a>.</p> <p>To install it, i found this method most hassle-free. You may also try <code>pip install</code> method described on the repo&rsquo;s <span class="caps">README</span>&nbsp;file.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>git clone https://github.com/jblakeman/apt-select.git </code></pre></div> <p>That&rsquo;s it. Now to execute it, just run the &ldquo;main&rdquo; Python&nbsp;file.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span><span class="nb">cd</span> apt-select <span class="hll"><span class="linenos" data-linenos="2 "></span><span class="gp">$ </span>./apt-select.py -c -t <span class="m">3</span> -m one-week-behind </span></code></pre></div> <p>We are choosing here the best 3 mirrors(due to <code>-t 3</code>) which are at most <code>one week behind</code> from the main Ubuntu server. For general purposes, that&rsquo;s good&nbsp;enough.</p> <p>It will choose one using the latency <span class="amp">&amp;</span> ping time, and also show servers&rsquo; bandwidth. Then the tool asks you to select new mirror from the <code>3</code> options came up. Usually, stick to the top option, hence <code>1</code>. For example in my case, it&nbsp;shows:</p> <div class="highlight"><pre><span></span><code><span class="hll"><span class="linenos" data-linenos=" 1 "></span><span class="gp">[khaled:~] $ </span>apt-select -c -t <span class="m">3</span> -m one-week-behind </span><span class="linenos" data-linenos=" 2 "></span><span class="go">Getting list of mirrors...done.</span> <span class="linenos" data-linenos=" 3 "></span><span class="go">Testing latency to mirror(s)</span> <span class="linenos" data-linenos=" 4 "></span><span class="go">[3/3] 100%</span> <span class="linenos" data-linenos=" 5 "></span><span class="go">Getting list of launchpad URLs...done.</span> <span class="linenos" data-linenos=" 6 "></span><span class="go">Looking up 3 status(es)</span> <span class="linenos" data-linenos=" 7 "></span><span class="go">[3/3] 100%</span> <span class="linenos" data-linenos=" 8 "></span><span class="go">1. mirror.dhakacom.com (current)</span> <span class="linenos" data-linenos=" 9 "></span><span class="go"> Latency: 1.89 ms</span> <span class="linenos" data-linenos="10 "></span><span class="go"> Org: dhakaCom Limited</span> <span class="linenos" data-linenos="11 "></span><span class="go"> Status: Up to date</span> <span class="linenos" data-linenos="12 "></span><span class="go"> Speed: 1 Gbps</span> <span class="linenos" data-linenos="13 "></span><span class="go">2. mirror.dhakacom.com</span> <span class="linenos" data-linenos="14 "></span><span class="go"> Latency: 1.96 ms</span> <span class="linenos" data-linenos="15 "></span><span class="go"> Org: dhakaCom Limited</span> <span class="linenos" data-linenos="16 "></span><span class="go"> Status: Up to date</span> <span class="linenos" data-linenos="17 "></span><span class="go"> Speed: 1 Gbps</span> <span class="linenos" data-linenos="18 "></span><span class="go">3. archive.ubuntu.com</span> <span class="linenos" data-linenos="19 "></span><span class="go"> Latency: 205.23 ms</span> <span class="linenos" data-linenos="20 "></span><span class="go"> Org: Canonical Ltd.</span> <span class="linenos" data-linenos="21 "></span><span class="go"> Status: Up to date</span> <span class="linenos" data-linenos="22 "></span><span class="go"> Speed: 100 Mbps</span> <span class="linenos" data-linenos="23 "></span><span class="go">Choose a mirror (1 - 3)</span> <span class="linenos" data-linenos="24 "></span><span class="go">&#39;q&#39; to quit 1</span> <span class="linenos" data-linenos="25 "></span><span class="go">New config file saved to /home/khaled/sources.list</span> </code></pre></div> <p>Then, the tool prepares a new <code>sources.list</code> file to replace the system&rsquo;s one&nbsp;with.</p> <p>Now, replace the file with the new one which will be now used by the <code>apt-get *</code> commands. As it overwrites a system config file, you need to do with <code>sudo</code>.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup <span class="o">&amp;&amp;</span> sudo mv sources.list /etc/apt/ </code></pre></div> <p>That&rsquo;s it. Now, all you update/upgrade will be fetched from the newly selected&nbsp;mirror.</p> <p>However, I highly recommend to run <code>update</code> once right&nbsp;away.</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sudo apt-get update </code></pre></div> <p>Then, only if you want, run <code>upgrade</code>:</p> <div class="highlight"><pre><span></span><code><span class="linenos" data-linenos="1 "></span><span class="gp">$ </span>sudo apt-get upgrade </code></pre></div> <hr> <h2 id="you-may-also-like">You may also like<a class="headerlink" href="#you-may-also-like" title="Permanent link">&para;</a></h2> <ul> <li><a href="https://blog.kmonsoor.com/open-source-as-if-you-gonna-die-tonight/?utm_source=related_footer&amp;utm_keyword=coding">Open Source as-if You Gonna Die&nbsp;Tonight</a></li> <li><a href="https://blog.kmonsoor.com/pelican-how-to-make-seo-friendly/?utm_source=related_footer&amp;utm_keyword=python">Pelican Static sites - <span class="caps">SEO</span>&nbsp;Optimization</a></li> <li><a href="https://blog.kmonsoor.com/generate-er-diagram-from-sql-database/?utm_source=related_footer&amp;utm_keyword=coding">Generate <span class="caps">ER</span> diagram from a <span class="caps">SQL</span>-based&nbsp;database</a></li> </ul>