参考:https://www.daweibro.com/node/142
什么是Ubuntu的软件源?
我们在使用Debian或者Ubuntu的apt-get工具来安装需要的软件时,其实就是从服务器获取需要安装的软件并把它安装在本地计算机的过程。所谓的软件源,就是我们获取软件的来源,它是定义在/etc/apt/sources.list文件里的。
1. sources.list
sources.list
位于/etc/apt
目录下,是一个普通可编辑的文本文件,保存了ubuntu软件更新的源服务器的地址。
2. sources.list.d/*.list
sources.list.d/*.list
位于/etc/apt/sources.list.d
目录下,为在单独文件中写入源的地址提供了一种方式,通常用来安装第三方的软件。
3. 换源
首先查看自己的Ubuntu系统的Codename(这一步很重要),直接导致你更新的源是否对你的系统起效果,查看方法:
lzb@lzb:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.6 LTS Release: 16.04 Codename: xenial
LSB是一套核心标准,它保证了LINUX发行版同LINUX应用程序之间的良好结合。它是 Linux 标准化领域中事实上的标准,制定了应用程序与运行环境之间的二进制接口。这里检测到LSB,模块没有获取,执行以下语句获取:
lzb@lzb:~$ sudo apt install lsb-core -y
lzb@lzb:~$ lsb_release -a
LSB Version: core-9.20160110ubuntu0.2-amd64:core-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
Release: 16.04
Codename: xenial
4. 镜像源获取
名称 分类 地址
阿里云
xenial http://mirrors.aliyun.com/ubuntu/dists/xenial/
xenial-backports http://mirrors.aliyun.com/ubuntu/dists/xenial-backports/
xenial-proposed http://mirrors.aliyun.com/ubuntu/dists/xenial-proposed/
xenial-security http://mirrors.aliyun.com/ubuntu/dists/xenial-security/
xenial-updates http://mirrors.aliyun.com/ubuntu/dists/xenial-updates/
清华
xenial https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/xenial
xenial-proposed https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/xenial-proposed
xenial-security https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/xenial-security
xenial-updates https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/xenial-updates
5. 选择合适的源
lzb@lzb:~$ ping mirrors.aliyun.com PING mirrors.aliyun.com.w.alikunlun.com (117.34.34.236) 56(84) bytes of data. 64 bytes from 117.34.34.236: icmp_seq=1 ttl=54 time=3.91 ms 64 bytes from 117.34.34.236: icmp_seq=2 ttl=54 time=4.18 ms 64 bytes from 117.34.34.236: icmp_seq=3 ttl=54 time=3.68 ms 64 bytes from 117.34.34.236: icmp_seq=4 ttl=54 time=7.89 ms
lzb@lzb:~$ ping mirrors.tuna.tsinghua.edu.cn PING cdnmirrors.s.tuna.tsinghua.edu.cn (101.6.8.193) 56(84) bytes of data. 64 bytes from 101.6.8.193: icmp_seq=1 ttl=241 time=19.4 ms 64 bytes from 101.6.8.193: icmp_seq=2 ttl=241 time=19.8 ms 64 bytes from 101.6.8.193: icmp_seq=3 ttl=241 time=21.4 ms 64 bytes from 101.6.8.193: icmp_seq=4 ttl=241 time=19.6 ms
发现阿里源速度比较快。
6. 备份并修改sources.list
sudo cp /etc/apt/sources.list /etc/apt/sources.beifen.list //备份原来的源信息
这里建立了两个源的文件,可以根据需要选择用哪一个。
sudo gedit /etc/apt/sources.qinghua.list //清华源的配置文件
清华源信息:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
sudo gedit /etc/apt/sources.aliyun.list //阿里源的配置文件
阿里源信息:
#deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
sudo cp sources.aliyun.list sources.list //选用阿里源
sudo apt-get update //刷新