Ubuntu下为什么要换源,如何换源

什么是源?

我们都知道下载文档或者是软件都要从一些站点去下载,这里的源可以理解为文档下载的服务器端对你提供的下载地址,源表明了当下载或者更新某些软件的时候要从指定的源站点去下载或者更新。

为什么要换源?

我之前安装的是ubuntu的中文版,加上这个系统安装后只是用过几天就没再用了,这个源的问题也就没有注意。这次重新要用的时候进行了系统重装,顺带装成了英文版,然后在进行语言更新的时候,有些语言包的下载速度真的是感人,就百度了一下,说是源的问题。

也就是说,使用不同的源可能会影响我们的下载速度,毕竟如果服务器放在自己家后院和别的国家下载速度应该会有点不一样的吧。所以这次把遇到的问题都给总结一下。

源在哪里?

首先我们先看一下我们原来的源,下边显示的就是我们电脑中sources.list的设置内容,该文件的地址一般是在 /etc/apt 下。

#deb cdrom:[Ubuntu 16.04.5 LTS _Xenial Xerus_ - Release amd64 (20180731)]/ xenial main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ xenial universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial universe
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu xenial partner
# deb-src http://archive.canonical.com/ubuntu xenial partner

deb http://security.ubuntu.com/ubuntu xenial-security main restricted
# deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
# deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse
# deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse

从上边的内容我们可以看到,有两个部分出现的频率很高,一个是网址 http://cn.archive.ubuntu.com/ubuntu/,我在进行实际语言包更新的时候发现更新的是从这个网址更新的,但是事实证明真的很慢,所以我猜测可能是英文版的ubuntu系统默认的就是这个源,我们之后要改变的也是这个部分。

还有一个出现次数很高的部分是 xenial,那么这个又是什么意思呢?我们都知道安装软件的时候要根据不同的系统安装不同的软件,比如win7和win10的软件有时候就会不太一样,那么对于ubuntu来说也是如此。ubuntu的每个发行版本都有自己的代号,我们需要找到自己系统的代号,然后再去找对应的源,可以用 ctrl+alt+t 打开终端,执行下面的命令可以看到自己的系统代号。

lsb_release -a

从终端执行的结果中我们能够看到自己的系统代号为 xenial,版本号为16.04,这就跟之前看到的对上了。

有哪些源?

以上的内容都搞明白了之后,剩下的就是看怎么去找到合适的源,毕竟对于我们使用来说,当然是越方便越好。我们首先查看一下我们能够是有的源有那哪些。查看网页

从上边我们能看到很多站点可以下载,并且往下拉可以看到一些失效的源也被列出来了。

怎么修改源?

我们已经知道有好多可以使用的源,那么怎么替换自己的源呢?还是这个网页,我们在最上边可以看到一个模板:16.04source的字眼,内容是:

deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
##測試版源
deb http://cn.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse
# 源碼
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
##測試版源
deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-proposed main restricted universe multiverse
# Canonical 合作夥伴和附加
deb http://archive.canonical.com/ubuntu/ xenial partner
deb http://extras.ubuntu.com/ubuntu/ xenial main

之后还有这么一句话:

可將 http://cn.archive.ubuntu.com/ubuntu/ 替換為下列任意服務器:

那么我们就知道是怎么操作了,比如替换成清华的源,就是:

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
##測試版源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# 源碼
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
##測試版源
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

怎么使用源?

我们已经修改好源了,那么我们将它配置到我们的系统中呢?很简单,就是将替换后的源替换原有的 sources.list 内容。

你也可以现将原有的文件备份:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

.bak 是 backup 的意思,表示备份文件。之后:

sudo gedit /etc/apt/sources.list

再将修改后的源替换文件中的内容。

更新软件列表:

sudo apt-get update

进行软件更新:

sudo apt-get upgrade

以上就是换源的全部过程了(由于我的 ubuntu 的发行版本号为16.04,对应的系统代号为 xenial,所以就以此为例)。

题外话

也有人提到其他的比较简单的方法,但是我没有尝试过,不知道正确性与否,姑且写在这里。具体方法是:

在 System Settings 中打开Software & Updates:

能够看到一些设置选项,给出了能够下载或更新的软件来源。其中 Other Software 也会给出系统软件之外的源目录(如果有的话)。

在下拉栏中找到 China,也能找到可用的源。

以上方法感兴趣的可以试一试。

参考资料:

1. https://wiki.ubuntu.org.cn/%E6%A8%A1%E6%9D%BF:16.04source

发布了77 篇原创文章 · 获赞 5 · 访问量 4912

猜你喜欢

转载自blog.csdn.net/SAKURASANN/article/details/104257996