当前位置:首页 » 《资源分享》 » 正文

Ubuntu更换国内镜像源

19 人参与  2024年09月28日 19:20  分类 : 《资源分享》  评论

点击全文阅读


官方镜像文档

阿里源

清华源

中科大源

网易163源

 1 从根目录进入到sources.list的文件目录中

cd /etc/apt

2 备份并更新sources.list

sudo cp sources.list sources.list.baksudo apt-get update

3 替换国内源

3.1 直接替换

sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' sources.listsudo sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' sources.list # 可选sudo sed -i 's/http:/https:/g' sources.list # 使用HTTPS可以有效避免国内运营商的缓存劫持

 3.2 手动替换

3.2.1 打开sources.list

sudo vim sources.list

3.2.2 注释或删除官方源,并复制如下中科大源到文件中

# 默认注释了源码仓库,如有需要可自行取消注释deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse# 预发布软件源,不建议启用# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

3.2.3 按下Esc后输入:wq!保存

若不使用sudo的话用:wq!保存时会出现/etc/apt/sources.list" E212: Can't open file for writing报错,使用如下命令保存并退出shell即可

:w !sudo tee % > /dev/null

4 执行更新

sudo apt-get update && sudo apt-get upgrade

5 其他国内源

常用的Ubuntu版本代号,这里以Ubuntu20.04为例,其它版本直接替换版本代号即可

Ubuntu 24.04:noble

Ubuntu 22.04:jammy

Ubuntu 20.04:focal

Ubuntu 18.04:bionic

 5.1 阿里源

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiversedeb-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 multiversedeb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiversedeb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

 5.2 清华源

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

 5.3 网易源

deb http://mirrors.163.com/ubuntu/ focal main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ focal-proposed main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ focal main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ focal-proposed main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse

点击全文阅读


本文链接:http://zhangshiyu.com/post/165963.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1