{"id":1433,"date":"2017-08-23T00:45:33","date_gmt":"2017-08-22T21:45:33","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=1433"},"modified":"2023-02-06T09:04:17","modified_gmt":"2023-02-06T06:04:17","slug":"creating-ubuntu-mirrors-using-apt-mirror","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/creating-ubuntu-mirrors-using-apt-mirror\/","title":{"rendered":"Creating Ubuntu Mirrors using apt-mirror"},"content":{"rendered":"\n<p>Creating Ubuntu Mirrors using apt-mirror: Hello good people. In this short tutorial, I\u2019ll show you how to setup local Ubuntu repository mirrors using apt-mirror. This usually comes in handy when you have a good number of Ubuntu servers in your network.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is&nbsp;apt-mirror?<\/h2>\n\n\n\n<p>This is a small tool that provides ability to mirror any parts (or even all) of Debian and Ubuntu GNU\/Linux distributions or any other apt sources which typically provided by open source developers.<\/p>\n\n\n\n<p>This guide will cover setting up repository mirrors for Ubuntu. A similar process applies to any other release of Ubuntu Linux.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install apt-mirror on Ubuntu<\/h2>\n\n\n\n<p>Installation requiremets:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Updated OS<\/li>\n\n\n\n<li>Adequate space. You can mount secondary disk in <strong><em>\/var\/spool\/apt-mirror<\/em><\/strong> (Repository contents storage path)<\/li>\n<\/ul>\n\n\n\n<p>Update package repository index<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<p>Then install apt-mirror package:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install apt-mirror<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring apt-mirror on Ubuntu<\/h2>\n\n\n\n<p>After installing apt-mirror, we can now proceed to do some configurations. This implies adding repository urls.<\/p>\n\n\n\n<p>Open the file&nbsp; \/etc\/apt\/mirror.list<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/apt\/mirror.list<\/code><\/pre>\n\n\n\n<p>Modify the file like below to sync official Ubuntu mirrors for 22.04\/20.04\/18.04 to your network.<\/p>\n\n\n\n<p>To sync<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"> Ubuntu 22.04<\/mark>, add the following lines to the file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>deb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">jammy-security main restricted universe multiverse\ndeb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">jammy-updates main restricted universe multiverse\ndeb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">jammy-proposed main restricted universe multiverse\ndeb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">jammy-backports main restricted universe multiverse\n\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">jammy-security main restricted universe multiverse\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">jammy-updates main restricted universe multiverse\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">jammy-proposed main restricted universe multiverse\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">jammy-backports main restricted universe multiverse<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">To sync<span class=\"has-inline-color has-vivid-red-color\"> Ubuntu 20.04<\/span>, add the following lines to the file.<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>deb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">focal-security main restricted universe multiverse\ndeb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">focal-updates main restricted universe multiverse\ndeb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">focal-proposed main restricted universe multiverse\ndeb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">focal-backports main restricted universe multiverse\n\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">focal-security main restricted universe multiverse\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">focal-updates main restricted universe multiverse\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">focal-proposed main restricted universe multiverse\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\">focal-backports main restricted universe multiverse<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">To sync <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Ubuntu 18.04<\/mark>, add the following line to the file.<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>deb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\"><meta charset=\"utf-8\">bionic-security main restricted universe multiverse\ndeb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\"><meta charset=\"utf-8\">bionic-updates main restricted universe multiverse\ndeb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\"><meta charset=\"utf-8\">bionic-proposed main restricted universe multiverse\ndeb http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\"><meta charset=\"utf-8\">bionic-backports main restricted universe multiverse\n\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\"><meta charset=\"utf-8\">bionic-security main restricted universe multiverse\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\"><meta charset=\"utf-8\">bionic-updates main restricted universe multiverse\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\"><meta charset=\"utf-8\">bionic-proposed main restricted universe multiverse\ndeb-src http:\/\/archive.ubuntu.com\/ubuntu <meta charset=\"utf-8\"><meta charset=\"utf-8\">bionic-backports main restricted universe multiverse<\/code><\/pre>\n\n\n\n<p>This will work both for 32 bit and 64 bit Ubuntu systems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Initiate sync manually<\/h3>\n\n\n\n<p>You can manually invoke apt-mirror command as well to initiate sync.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/usr\/bin\/apt-mirror<\/code><\/pre>\n\n\n\n<p>Sample execution output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Downloading 340 index files using 20 threads...\nBegin time: Tue Jan 18 18:44:40 2022\n&#91;20]... &#91;19]... &#91;18]... &#91;17]... &#91;16]... &#91;15]... &#91;14]... &#91;13]... &#91;12]... &#91;11]... &#91;10]... &#91;9]... &#91;8]... &#91;7]... &#91;6]... &#91;5]... &#91;4]... &#91;3]... &#91;2]... &#91;1]... &#91;0]...\nEnd time: Tue Jan 18 18:44:41 2022\n\nProcessing translation indexes: &#91;TTTTTTTT]\n\nDownloading 567 translation files using 20 threads...\nBegin time: Tue Jan 18 18:44:41 2022\n&#91;20]... &#91;19]... &#91;18]... &#91;17]... &#91;16]... &#91;15]... &#91;14]... &#91;13]... &#91;12]... &#91;11]... &#91;10]... &#91;9]... &#91;8]... &#91;7]... &#91;6]... &#91;5]... &#91;4]... &#91;3]... &#91;2]... &#91;1]... &#91;0]...\nEnd time: Tue Jan 18 18:44:42 2022\n\nProcessing DEP-11 indexes: &#91;DDDDDDDD]\n\nDownloading 104 dep11 files using 20 threads...\nBegin time: Tue Jan 18 18:44:42 2022\n&#91;20]... &#91;19]... &#91;18]... &#91;17]... &#91;16]... &#91;15]... &#91;14]... &#91;13]... &#91;12]... &#91;11]... &#91;10]... &#91;9]... &#91;8]... &#91;7]... &#91;6]... &#91;5]... &#91;4]... &#91;3]... &#91;2]... &#91;1]... &#91;0]...\nEnd time: Tue Jan 18 18:44:42 2022\n\nProcessing indexes: &#91;SSSSPPPPPPPP]\n........<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Automate packages sync using cron job<\/h3>\n\n\n\n<p>Write cron job that runs daily to automatically do sync:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ <span class=\"has-inline-color has-pale-pink-color\">sudo crontab -e<\/span>\n50 3  * * * \/usr\/bin\/apt-mirror<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Serving Repositories with nginx:<\/h3>\n\n\n\n<p>Install Nginx web server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install nginx<\/code><\/pre>\n\n\n\n<p>Start and enable the service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable nginx\nsudo systemctl start nginx<\/code><\/pre>\n\n\n\n<p>Configure Nginx to serve Ubuntu repositories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/nginx\/conf.d\/mirrors.conf<\/code><\/pre>\n\n\n\n<p>The content should look similar to below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n listen 80;\n server_name <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">mirror.domain.com<\/mark>; \n root \/var\/spool\/apt-mirror\/mirror\/archive.ubuntu.com\/;\n\n location \/ {\n   autoindex on;\n }\n}<\/code><\/pre>\n\n\n\n<p>Restart nginx<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart nginx<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring Clients to use configured mirro<\/h3>\n\n\n\n<p>We&#8217;ll use <strong><em>Ubuntu 20.04<\/em><\/strong> as an example in client machine configuration.<\/p>\n\n\n\n<p>Edit the default sources configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/etc\/apt\/sources.list<\/code><\/pre>\n\n\n\n<p>Set repositories to configured one.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#------------------------------------------------------------------------------#\n# OFFICIAL UBUNTU REPOS #\n#------------------------------------------------------------------------------#\n\n###### Ubuntu Main Repos\ndeb http:\/\/<span class=\"has-inline-color has-vivid-cyan-blue-color\">mirror.domain.com<\/span>\/ubuntu\/ focal main restricted universe multiverse\n\n###### Ubuntu Security Repos\ndeb http:\/\/<meta charset=\"utf-8\"><span class=\"has-inline-color has-vivid-cyan-blue-color\">mirror.domain.com<\/span>\/ubuntu focal-security main restricted universe multiverse\n\n###### Ubuntu Update Repos\ndeb http:\/\/<meta charset=\"utf-8\"><span class=\"has-inline-color has-vivid-cyan-blue-color\">mirror.domain.com<\/span>\/ubuntu\/ focal-updates main restricted universe multiverse\ndeb http:\/\/<meta charset=\"utf-8\"><span class=\"has-inline-color has-vivid-cyan-blue-color\">mirror.domain.com<\/span>\/ubuntu\/ focal-backports main restricted universe multiverse<\/code><\/pre>\n\n\n\n<p>Test if the repos configured are working:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update<\/code><\/pre>\n\n\n\n<p>See more articles below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/computingforgeeks.com\/cheap-ethernet-gigabit-switches-with-vlan-to-buy\/\" target=\"_blank\" rel=\"noreferrer noopener\">Cheap Ethernet Gigabit Switches with VLAN to buy<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/best-laptops-with-intel-11th-gen-cpu\/\" target=\"_blank\" rel=\"noreferrer noopener\">8 Best Laptops with Intel 11th Gen CPU<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/fast-wireless-charger-stands-for-iphone\/\" target=\"_blank\" rel=\"noreferrer noopener\">5 Cheap Fast Wireless Charger Stands for iPhone<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Creating Ubuntu Mirrors using apt-mirror: Hello good people. In this short tutorial, I\u2019ll show you how to setup local Ubuntu repository mirrors using apt-mirror. This usually comes in handy when you have a good number of Ubuntu servers in your network. What is&nbsp;apt-mirror? This is a small tool that provides ability to mirror any parts &#8230; <a title=\"Creating Ubuntu Mirrors using apt-mirror\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/creating-ubuntu-mirrors-using-apt-mirror\/\" aria-label=\"Read more about Creating Ubuntu Mirrors using apt-mirror\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":1434,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,47,81],"tags":[277,182,278],"class_list":["post-1433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-tutorials","category-linux","category-ubuntu","tag-apt-mirror","tag-mirrors","tag-ubuntu-mirrors"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/1433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=1433"}],"version-history":[{"count":0,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/1433\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/1434"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=1433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=1433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=1433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}