【Ubuntu】如何将Ubuntu软件源切换到国内源?

为什么切换软件源?

当初次部署Ubuntu镜像时,会发现更新软件时速度非常慢,因为Ubuntu的软件都来自与国外,所下载或更新软件时的速度非常慢,此时就可以选择切换到国内的软件源来解决此问题。

更新Ubuntu软件源

国内的软件源有很多,比如一些互联网公司及各大高校等,较为常用的有阿里云源和清华源

阿里云源: http://mirrors.aliyun.com/ubuntu/
清华源: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

1.获取软件源配置(二者任选其一)

  • 清华源:

打开清华源链接,切换到自己所使用的Ubuntu版本,复制文本框中的配置信息

image

20.04 LTS版本:

# 默认注释了源码镜像以提高 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

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
  • 阿里云源:

打开阿里云链接

image

image

点击进入Ubuntu

image

Ubuntu 20.04配置:

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

2.修改配置文件sources.list

现将原sources.list备份一下(如果后续修改错误还可以替换回来)

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

使用编辑器打开sources.list文件,并将1中复制的配置信息替换到sources.list中,然后保存退出

sudo gedit /etc/apt/sources.list

image

3.更新软件列表并升级软件

检索更新软件列表

sudo apt-get update

可以看到源都已经更新为清华源,如果使用的是阿里云源的配置,那此处就会从阿里云源中拉取:

image

更新软件

sudo apt-get upgrade

至此完成更新Ubuntu软件源整个过程

posted @   Emma1111  阅读(980)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示