1.事件背景

  事情起因是因为我想安装xvfb,执行sudo apt-get install xvfb发现安装报错,看报错原因是被墙导致,因为我用的默认源也没有挂代理;然后就百度,发现都是互相抄,什么换阿里源啊,163源、中科源之类,我都试过,并且发现这些源在更新过程会有一些错误或者更新被忽略,导致我再次执行sudo apt-get install -y xvfb报错说未找到包。

  我就接着百度,然后有一条评论给了我灵感,既然默认源切换国区可以安装包,那么我把默认域名us.ports.ubuntu.com换成国内的,us代表美国,zh代表中国,我就试了zh.ports.ubuntu.com,发现真的可以!

2. 替换方法

Ps:我使用的系统Ubuntu 18.04 LTS

1.先对默认源进行备份

  1. sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

2.进入默认源编辑

  1. sudo vi /etc/apt/sources.list

3.全局替换

3.1 按ESC键输入:
 3.2 粘贴下面批量替换命令

  1. %s/us\./zh\./g

4. 保存后再执行更新源命令

执行完上述操作步骤后再输入你想安装的包,会发现可以安装了!

最后我想吐槽那些原封不动的抄袭者,虽然转载他人文章可以备份,但是当某一天你想上网查找一个问题的解决方法时,发现全网都是同一个答案,还是一模一样的,而想要找到真正有用的答案无异于海底捞针!

3. 完整源文件备份

默认源文件

  1. #
  2.  
  3. # deb cdrom:[Ubuntu-Server 18.04.3 LTS _Bionic Beaver_ - Release arm64 (20190805)]/ bionic main restricted
  4.  
  5. #deb cdrom:[Ubuntu-Server 18.04.3 LTS _Bionic Beaver_ - Release arm64 (20190805)]/ bionic main restricted
  6.  
  7. # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
  8. # newer versions of the distribution.
  9. deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic main restricted
  10. # deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic main restricted
  11.  
  12. ## Major bug fix updates produced after the final release of the
  13. ## distribution.
  14. deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
  15. # deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
  16.  
  17. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  18. ## team. Also, please note that software in universe WILL NOT receive any
  19. ## review or updates from the Ubuntu security team.
  20. deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic universe
  21. # deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic universe
  22. deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
  23. # deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
  24.  
  25. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  26. ## team, and may not be under a free licence. Please satisfy yourself as to
  27. ## your rights to use the software. Also, please note that software in
  28. ## multiverse WILL NOT receive any review or updates from the Ubuntu
  29. ## security team.
  30. deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic multiverse
  31. # deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic multiverse
  32. deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
  33. # deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
  34.  
  35. ## N.B. software from this repository may not have been tested as
  36. ## extensively as that contained in the main release, although it includes
  37. ## newer versions of some applications which may provide useful features.
  38. ## Also, please note that software in backports WILL NOT receive any review
  39. ## or updates from the Ubuntu security team.
  40. deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
  41. # deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
  42.  
  43. ## Uncomment the following two lines to add software from Canonical's
  44. ## 'partner' repository.
  45. ## This software is not part of Ubuntu, but is offered by Canonical and the
  46. ## respective vendors as a service to Ubuntu users.
  47. # deb http://archive.canonical.com/ubuntu bionic partner
  48. # deb-src http://archive.canonical.com/ubuntu bionic partner
  49.  
  50. deb http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
  51. # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
  52. deb http://ports.ubuntu.com/ubuntu-ports bionic-security universe
  53. # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security universe
  54. deb http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse
  55. # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse

修改后国内可用源文件

  1. #
  2.  
  3. # deb cdrom:[Ubuntu-Server 18.04.3 LTS _Bionic Beaver_ - Release arm64 (20190805)]/ bionic main restricted
  4.  
  5. #deb cdrom:[Ubuntu-Server 18.04.3 LTS _Bionic Beaver_ - Release arm64 (20190805)]/ bionic main restricted
  6.  
  7. # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
  8. # newer versions of the distribution.
  9. deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic main restricted
  10. # deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic main restricted
  11.  
  12. ## Major bug fix updates produced after the final release of the
  13. ## distribution.
  14. deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
  15. # deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
  16.  
  17. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  18. ## team. Also, please note that software in universe WILL NOT receive any
  19. ## review or updates from the Ubuntu security team.
  20. deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic universe
  21. # deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic universe
  22. deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
  23. # deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
  24.  
  25. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  26. ## team, and may not be under a free licence. Please satisfy yourself as to
  27. ## your rights to use the software. Also, please note that software in
  28. ## multiverse WILL NOT receive any review or updates from the Ubuntu
  29. ## security team.
  30. deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic multiverse
  31. # deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic multiverse
  32. deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
  33. # deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
  34.  
  35. ## N.B. software from this repository may not have been tested as
  36. ## extensively as that contained in the main release, although it includes
  37. ## newer versions of some applications which may provide useful features.
  38. ## Also, please note that software in backports WILL NOT receive any review
  39. ## or updates from the Ubuntu security team.
  40. deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
  41.  
  42. # deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
  43.  
  44. ## Uncomment the following two lines to add software from Canonical's
  45. ## 'partner' repository.
  46. ## This software is not part of Ubuntu, but is offered by Canonical and the
  47. ## respective vendors as a service to Ubuntu users.
  48. # deb http://archive.canonical.com/ubuntu bionic partner
  49. # deb-src http://archive.canonical.com/ubuntu bionic partner
  50.  
  51. deb http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
  52. # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
  53. deb http://ports.ubuntu.com/ubuntu-ports bionic-security universe
  54. # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security universe
  55. deb http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse
  56. # deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse
 

Linux 更换国内源的更多相关文章

  1. kali linux 更换国内源报GPG error解决办法

    wget -q -O - https://archive.kali.org/archive-key.asc | apt-key add

  2. yum更换国内源、yum下载rpm包、源码包安装 使用介绍

    第5周第4次课(4月19日) 课程内容: 7.6 yum更换国内源7.7 yum下载rpm包7.8/7.9 源码包安装 7.6 yum更换国内源 当yum仓库的软件不好用时,例如很多yum源都是国外的 ...

  3. Ubuntu18.04更换国内源(阿里,网易,中科大,清华等源)

    1.备份 备份/etc/apt/sources.list文件 mv /etc/apt/sources.list /etc/apt/sourses.list.backup 2.新建 新建/etc/apt ...

  4. pip/pip3更换国内源

    pip/pip3更换国内源 用途:pip更换为国内源,可以大大的提高安装成功率和速度. Windows更换pip/pip3源 打开目录:%appdata% 新增pip文件夹,新建pip.ini文件 给 ...

  5. Ubuntu18.04更换国内源

    Ubuntu18.04更换国内源 Ubuntu本身的源使用的是国内的源,下载速度比较慢,不像CentOS一样yum安装的时候对镜像站点进项选择, 所以选择了更换成国内的源. 以下内容整合自网络 备份/ ...

  6. yum更换国内源 yum下载rpm包 源码包安装

    7.6 yum更换国内源 7.7 yum下载rpm包 7.8/7.9 源码包安装 yum更换国内源 cd  /etc/yum.repo.d/ 删除源 rm -f   dvd.repo rm -f  C ...

  7. yum更换国内源及yum下载rpm包

    一.yum更换国内源 运维开发技术交流群欢迎大家加入一起学习(QQ:722381733) 1.前往yum文件路径地址 [root@web1 ~]# cd /etc/yum.repos.d/ [root ...

  8. FreeBSD更换国内源(pkg源使用台湾源,中科大源备用)

    安装后第一件事就是更换国内源,不然后面安装桌面等,不用国内源下载太慢. 修改 pkg 源 创建用户级 pkg 源目录:mkdir -p /usr/local/etc/pkg/repos ee /usr ...

  9. Docker(Docker Toolbox)配置镜像加速更换国内源

    自己当时装的是Win10专业工作室版本,不知道为什么不支持window for docker, 所以选择了Docker Toolbox 的方式,主要是为了学习,虽然这种方式是不建议安装的,但是基础的学 ...

随机推荐

  1. 聊聊C#中的composite模式

    写在前面 Composite组合模式属于设计模式中比较热门的一个,相信大家对它一定不像对访问者模式那么陌生,毕竟谁又没有遇到过树形结构呢.不过所谓温故而知新,我们还是从一个例子出发,起底一下这个模式吧 ...

  2. Pytorch中的Sort的使用

    >>> a = torch.randn(3,3)>>> atensor([[ 0.5805, 0.1940, 1.2591], [-0.0863, 0.5350, ...

  3. MAC帧的格式&&wireshark分析MAC帧

    MAC帧的格式 MAC帧较为简单,由五个字段组成 目的地址:6字节 源地址:6字节 类型字段:2字节,用来标志上一层使用的是什么协议,以便把收到的MAC地址帧的数据交给上一层的这个协议. 数据字段:其 ...

  4. 12.1 Android Studio如何手动下载Gradle文件

    实际操作过程中,可能由于各方面原因,导致Gradle无法下载,或者下载比较慢,这个时候,其实我们可以手动下载,或者找一个最近的版本,替换他. 确认要下载的版本 不论是用命令编译Android项目,还是 ...

  5. CSS Houdini:用浏览器引擎实现高级CSS效果

    vivo 互联网前端团队-Wei Xing Houdini被称之为Magic of styling and layout on the web,看起来十分神秘,但实际上,Houdini并非什么神秘组织 ...

  6. FastASR——PaddleSpeech的C++实现

    FastASR 基于PaddleSpeech所使用的conformer模型,使用C++的高效实现模型推理,在树莓派4B等ARM平台运行也可流畅运行. 项目简介 本项目仅实现了PaddleSpeech ...

  7. cx_Oracle.DatabaseError: ORA-28759: failure to open file

    找了好久这个问题,有人说是tcps的问题,需要自己生成证书什么的,后来才发现原来是 钱包文件路径 的问题,钱包文件解压后必须放在instantclien/network/admin下,在Windows ...

  8. pyinstaller打包一些三方库后,报资源不存在

    在目录site-packages\PyInstaller\hooks下新建对应文件hook-对应三方库名字.py,如hook-ngender.py 编辑hook-ngender.py: from Py ...

  9. dynamic + shardingsphere(4.1.1) 实现动态分库分表

    1. 主要依赖: <dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-da ...

  10. 从零开始Blazor Server(2)--整合数据库

    开篇 上一篇文章我们留了个尾巴,没有把freesql整合进去,这篇文章我们来整合. 目前的思路呢,是做一个简单的四不像的RABC,也有用户.角色. 权限三部分. 但是其中每个用户只有一个角色,即用户和 ...