Ubuntu apt更换国内源

Ubuntu apt更换国内源

Ubuntu apt默认的下载源是
cn.archive.ubuntu.com/ubuntu/
这是一个国外的网站,下载速度比较慢,我们将下载源更换为国内镜像站,提高下载速度和连接的稳定性。

apt下载源的配置文件是

/etc/apt/sources.list

使用命令

cat /etc/apt/sources.list

可以看到其中的内容。

欲更换下载源,替换该文件中的默认源为国内源即可。笔者采用的是清华tuna源。

为保险起见,修改文件前,先备份一下文件

cp /etc/apt/sources.list /etc/apt/sources_bak.list

然后

sudo gedit /etc/apt/sources.list

或者

sudo vim /etc/apt/sources.list

将文件内容替换为(以清华源ipv6镜像站为例,其他国内镜像站类似)

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

然后更新一下源

sudo apt-get update

可以发现命令输出中的下载源已经变成了清华tuna源mirrors.tuna.tsinghua.edu.cn/ubuntu/

之后用apt-get install下载软件就是使用国内的清华源了。

1. 打开终端,输入以下命令备份原有列表文件: ``` sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak ``` 2. 编辑列表文件: ``` sudo gedit /etc/apt/sources.list ``` 3. 将原有的地址替换为国内地址,例如: ``` # 默认 deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse # 国内 deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse ``` 4. 保存并关闭文件,更新列表: ``` sudo apt update ``` 5. 完成。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值