终端一行命令更换ubuntu国内镜像源

sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
sudo sed -i 's/cn.archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
sudo sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

其他:

sudo curl -L https://github.com/AndyYoungDev/ubuntu-aliyun-sources/releases/download/shell/change.sh | bash
sudo: /etc/sudoers.d 可被任何人写
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   648  100   648    0     0    708      0 --:--:-- --:--:-- --:--:--   707
100  1354  100  1354    0     0    555      0  0:00:02  0:00:02 --:--:--  1707
                                  _oo0oo_
                                 088888880
                                 88" . "88
                                 (| -_- |)
                                  0\ = /0
                               ___/'---'\___
                             .' \\|     |// '.
                            / \\|||  :  |||// \
                           /_ ||||| -:- |||||- \
                          |   | \\\  -  /// |   |
                          | \_|  ''\---/''  |_/ |
                          \  .-\__  '-'  __/-.  /
                        ___'. .'  /--.--\  '. .'___
                     ."" '<  '.___\_<|>_/___.' >'  "".
                    | | : '-  \'.;'\ _ /';.'/ - ' : | |
                    \  \ '_.   \_ __\ /__ _/   .-' /  /
                ====='-.____'.___ \_____/___.-'____.-'=====
                                  '=---='


              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Need Root!

手动修改ubuntu源:备份如下:
sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

内容为:

# deb cdrom:[Ubuntu 20.04.3 LTS _Focal Fossa_ - Release amd64 (20210819)]/ focal main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted
# deb-src http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security universe
# deb-src http://security.ubuntu.com/ubuntu focal-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security multiverse
# deb-src http://security.ubuntu.com/ubuntu focal-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

修改:sudo gedit /etc/apt/sources.list

内容如下:

阿里ubuntu源20.04

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-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security 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-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed 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

更新:

sudo apt-get update
sudo apt-get -f install
sudo apt-get upgrade

测试结果:

正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
正在计算更新... 完成
下列软件包将被升级:
  cpp-9 curl dpkg dpkg-dev evolution-data-server evolution-data-server-common g++-9 gcc-9 gcc-9-base gfortran-9 gir1.2-nm-1.0 libasan5 libc-bin libc-dev-bin libc6 libc6:i386
  libc6-dbg libc6-dev libc6-i386 libcamel-1.2-62 libcurl3-gnutls libcurl3-gnutls:i386 libcurl4 libdpkg-perl libdrm-amdgpu1 libdrm-amdgpu1:i386 libdrm-common libdrm-intel1
  libdrm-intel1:i386 libdrm-nouveau2 libdrm-nouveau2:i386 libdrm-radeon1 libdrm-radeon1:i386 libdrm2 libdrm2:i386 libebackend-1.2-10 libebook-1.2-20 libebook-contacts-1.2-3
  libecal-2.0-1 libedata-book-1.2-26 libedata-cal-2.0-1 libedataserver-1.2-24 libedataserverui-1.2-2 libegl-mesa0 libegl1-mesa-dev libgbm1 libgcc-9-dev libgfortran-9-dev
  libgl1-mesa-dev libgl1-mesa-dri libgl1-mesa-dri:i386 libglapi-mesa libglapi-mesa:i386 libglx-mesa0 libglx-mesa0:i386 libgtkmm-3.0-1v5 libnm0 libobjc-9-dev libosmesa6
  libosmesa6:i386 libstdc++-9-dev libx11-6 libx11-6:i386 libx11-data libx11-dev libx11-xcb1 libx11-xcb1:i386 libxatracker2 linux-libc-dev locales mesa-va-drivers
  mesa-va-drivers:i386 mesa-vdpau-drivers mesa-vdpau-drivers:i386 mesa-vulkan-drivers mesa-vulkan-drivers:i386 network-manager network-manager-config-connectivity-ubuntu
  secureboot-db snapd
升级了 80 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
需要下载 176 MB 的归档。
解压缩后会消耗 132 MB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 dpkg amd64 1.19.7ubuntu3.1 [1,128 kB]
获取:2 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libc6-dbg amd64 2.31-0ubuntu9.4 [20.1 MB]
获取:3 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libc6-i386 amd64 2.31-0ubuntu9.4 [2,724 kB]                                                                  
获取:4 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libc6-dev amd64 2.31-0ubuntu9.4 [2,522 kB]                                                                   
获取:5 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libc-dev-bin amd64 2.31-0ubuntu9.4 [71.8 kB]                                                                 
获取:6 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 linux-libc-dev amd64 5.4.0-97.110 [1,126 kB]                                                                 
获取:7 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libc6 amd64 2.31-0ubuntu9.4 [2,726 kB]                                                                       
获取:8 http://mirrors.aliyun.com/ubuntu focal-proposed/main i386 libc6 i386 2.31-0ubuntu9.4 [2,580 kB]                                                                         
获取:9 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 locales all 2.31-0ubuntu9.4 [3,870 kB]                                                                       
获取:10 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libc-bin amd64 2.31-0ubuntu9.4 [635 kB]                                                                     
获取:11 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libdrm-common all 2.4.107-8ubuntu1~20.04.1 [5,408 B]                                                        
获取:12 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libdrm2 amd64 2.4.107-8ubuntu1~20.04.1 [34.1 kB]                                                            
获取:13 http://mirrors.aliyun.com/ubuntu focal-proposed/main i386 libdrm2 i386 2.4.107-8ubuntu1~20.04.1 [37.5 kB]                                                              
获取:14 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libx11-data all 2:1.6.9-2ubuntu1.3 [113 kB]                                                                 
获取:15 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libx11-dev amd64 2:1.6.9-2ubuntu1.3 [645 kB]                                                                
获取:16 http://mirrors.aliyun.com/ubuntu focal-proposed/main i386 libx11-6 i386 2:1.6.9-2ubuntu1.3 [599 kB]                                                                    
获取:17 http://mirrors.aliyun.com/ubuntu focal-proposed/main amd64 libx11-6 amd64 2:1.6.9-2ubuntu1.3 [577 kB]                                 

参考:
https://zhuanlan.zhihu.com/p/381919621
https://blog.csdn.net/weixin_43960643/article/details/100748351

ubuntu 20.04修改数据源配置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在Ubuntu更换镜像,可以按照以下步骤进行操作: 1. 打开终端:在Ubuntu桌面上,按下Ctrl + Alt + T键组合,或者点击左上角的“应用程序”图标,然后搜索并打开“终端”。 2. 备份原始列表文件:在终端中运行以下命令来备份原始列表文件: ``` sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup ``` 3. 编辑列表文件:使用文本编辑器(如nano或gedit)编辑列表文件。运行以下命令使用nano编辑器打开文件: ``` sudo nano /etc/apt/sources.list ``` 4. 更换镜像:在列表文件中找到以“http://archive.ubuntu.com/”开头的行,并将其替换为你选择的镜像。你可以选择一个靠近你所在地区的镜像或者使用官方推荐的镜像。例如,如果你在中国,你可以使用清华大学的镜像,将行替换为: ``` deb 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 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 ``` 5. 保存和关闭文件:按下Ctrl + O保存文件,在nano编辑器中按下Enter确认,然后按下Ctrl + X关闭编辑器。 6. 更新软件包列表:运行以下命令来更新软件包列表,使更改生效: ``` sudo apt update ``` 现在,你的Ubuntu系统将使用新的镜像来下载软件包和更新。请注意,如果你遇到任何问题,可以恢复到原始列表文件(通过运行`sudo cp /etc/apt/sources.list.backup /etc/apt/sources.list`命令)或使用其他可用的镜像

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

源代码杀手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值