Ubuntu更换apt镜像源

在ubuntu中,默认使用 ubuntu 的官方源http://archive.ubuntu.com/,但是这个官方源在国内下载的速度太慢,甚至只有几十k。于是考虑更换apt源加快下载速度

国内可用镜像源站点很多,可以参考文章国内镜像站推荐,这里以阿里镜像源作ubuntu的apt源

更换镜像源步骤

在 Ubuntu 系统中,可以通过修改/etc/apt/sources.list文件内容来修改 apt 源,通常在镜像站中也给出了更改镜像源的方法,比如阿里镜像站的更换说明:Ubuntu 镜像更换

图形界面配置

新手推荐使用图形界面配置: 系统设置 -> 软件和更新 选择下载服务器 -> “mirrors.aliyun.com”

无图形界面手动更改

  1. 首先备份 sources.list 文件,避免在意外出错情况下能够还原
<div class="code-toolbar">
<pre class=" language-bash"><code class=" hljs language-bash"><span class="token builtin class-name">cd</span> /etc/apt/
<span class="token function">sudo</span> <span class="token function">cp</span> sources.list sources.list.bak</code></pre>
</div>
  1. 修改 sources.list 文件内容
<div class="code-toolbar">
<pre class=" language-bash"><code class=" hljs language-bash"><span class="token function">sudo</span> <span class="token function">vim</span> sources.list</code></pre>
</div>

替换默认的 http://archive.ubuntu.com/ 为 mirrors.aliyun.com
以Ubuntu 14.04.5 LTS为例,最后的效果如下:

<div class="code-toolbar">
<pre class=" language-text"><code class=" language-text">deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe</code></pre>
</div>

ubuntu 16.04 配置如下

<div class="code-toolbar">
<pre class=" language-text"><code class=" language-text">deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe</code></pre>
</div>

ubuntu 18.04(bionic) 配置如下

<div class="code-toolbar">
<pre class=" language-text"><code class=" language-text">deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse</code></pre>
</div>
  1. 更新 apt 本地索引
<div class="code-toolbar">
<pre class=" language-bash"><code class=" hljs language-bash"><span class="token function">sudo</span> <span class="token function">apt</span> update</code></pre>
</div>

这个速度变化很明显了,甚至达到了2M多每秒

image.png
事实上,对于其他 Linux 发行版更改镜像源,方法也是大同小异的(如 Redhat 系的 yum)

参考:
https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.53322f70NQyRxh

© 版权声明
THE END
喜欢就支持一下吧
点赞6赞赏 分享
评论 共1条

请登录后发表评论

    请登录后查看评论内容