ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux 更换国内源

2022-02-02 12:32:09  阅读:207  来源: 互联网

标签:http 更换 Linux 国内 bionic ubuntu deb com ports


 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.先对默认源进行备份

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

2.进入默认源编辑

sudo vi /etc/apt/sources.list

3.全局替换

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

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

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

 

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

 

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

 

3. 完整源文件备份

默认源文件

 

#

# deb cdrom:[Ubuntu-Server 18.04.3 LTS _Bionic Beaver_ - Release arm64 (20190805)]/ bionic main restricted

#deb cdrom:[Ubuntu-Server 18.04.3 LTS _Bionic Beaver_ - Release arm64 (20190805)]/ bionic main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic main restricted
# deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
# deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic-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://us.ports.ubuntu.com/ubuntu-ports/ bionic universe
# deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic universe
deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
# deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic-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://us.ports.ubuntu.com/ubuntu-ports/ bionic multiverse
# deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic multiverse
deb http://us.ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
# deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic-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://us.ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src http://us.ports.ubuntu.com/ubuntu-ports/ bionic-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 bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports bionic-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security universe
deb http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse

 

修改后国内可用源文件

# 

# deb cdrom:[Ubuntu-Server 18.04.3 LTS _Bionic Beaver_ - Release arm64 (20190805)]/ bionic main restricted

#deb cdrom:[Ubuntu-Server 18.04.3 LTS _Bionic Beaver_ - Release arm64 (20190805)]/ bionic main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic main restricted
# deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-updates main restricted
# deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-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://zh.ports.ubuntu.com/ubuntu-ports/ bionic universe
# deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic universe
deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-updates universe
# deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-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://zh.ports.ubuntu.com/ubuntu-ports/ bionic multiverse
# deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic multiverse
deb http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-updates multiverse
# deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-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://zh.ports.ubuntu.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
    
# deb-src http://zh.ports.ubuntu.com/ubuntu-ports/ bionic-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 bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports bionic-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security universe
deb http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse

 

 

 

标签:http,更换,Linux,国内,bionic,ubuntu,deb,com,ports
来源: https://www.cnblogs.com/1314h/p/15860214.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有