Ubuntu 更换 apt 镜像源

Ubuntu 更换 apt 镜像源


apt 是 Ubuntu 系的包管理工具,一般默认使用 ubuntu 的官方源  http://archive.ubuntu.com/ 在国内下载的速度慢到让人想砸电脑,可以更换为国内的镜像源以提高 apt 的下载速度;

国内镜像源推荐

阿里 OPSX 源: https://opsx.alibaba.com/mirror
网易 163 源: http://mirrors.163.com/
中科大 USTC 源: https://mirrors.ustc.edu.cn/
ubuntu 中国官方源(搜狐): http://mirrors.sohu.com/help/ubuntu.html

※一般在这些镜像源站点,点击需要的镜像源右边的 help 按钮,就会给出该镜像源相关仓库的 URL(甚至包括更改镜像源的操作步骤);

更换镜像源步骤

对于 Ubuntu ,可以通过修改   /etc/apt/sources.list 文件内容来修改 apt 源,以下以更换为 OPSX 的 Ubuntu 镜像源为例;
  • 备份 sources.list 文件
cd /etc/apt/
sudo cp sources.list sources.list.bak
  • 修改 sources.list 文件内容
sudo vim sources.list
将  http://archive.ubuntu.com/  部分更换为获取到的国内镜像源地址,更换后示例内容如下:
eb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb 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 main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  • 更新 apt 本地索引
sudo apt-get update

※至于其他 Linux 发行版更改镜像源,方法也是大同小异的(如 Redhat 系的 yum);


关于 Ubuntu sources.list 文件中关键字的说明

deb  描述一个源软件二进制库
deb-src描述一个源软件库源代码库
main完全的自由软件
restricted不完全的自由软件
universeubuntu官方不提供支持与补丁,全靠社区支持
muitiverse非自由软件,完全不提供支持和补丁



要在Ubuntu系统中更换清华镜像源,可以按照以下步骤操作: 1. 打开终端,执行以下命令备份原有的列表文件: ``` sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak ``` 2. 执行以下命令编辑列表文件: ``` sudo gedit /etc/apt/sources.list ``` 3. 将文件内容替换为以下内容: ``` # 默认注释了码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse ``` 注意:以上内容为Ubuntu 20.04 LTS版本的列表,其他版本可能有所不同。 4. 保存文件并退出编辑器。 5. 执行以下命令新软件包列表: ``` sudo apt update ``` 现在,你的Ubuntu系统就已经使用清华镜像源了。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值