一、Centos7更改為國內源
注意:我通常習慣在系統安裝好之后就把源給改過來了,但我習慣創建一個只帶基礎服務的系統,所以一些常用的功能沒有。所以在更改源之前必須保證有wget和vim或vi這兩個工具,否則你把yum源改了之后才發現無法獲取新的yum源就比較痛苦了
首先備份本地yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
獲取阿里yum源配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
運行yum makecache生成緩存
yum makecache
更新和升級
yum update
二、Ubuntu修改為國內源
首先查看當前系統代號
lsb_release -c
或者
lsb_release -a

具體對應代碼可參照下表
| 版本 |
別名(codename) |
發布日期 |
| 4.10 |
Warty Warthog(長疣的疣豬) |
2004年10月20日 |
| 5.04 |
Hoary Hedgehog(灰白的刺蝟) |
2005年4月8日 |
| 5.10 |
Breezy Badger(活潑的獾) |
2005年10月13日 |
| 6.06 |
Dapper Drake(整潔的公鴨) |
2006年6月1日(LTS) |
| 6.10 |
Edgy Eft(急躁的水蜥) |
2006年10月6日 |
| 7.04 |
Feisty Fawn(壞脾氣的小鹿) |
2007年4月19日 |
| 7.10 |
Gutsy Gibbon(勇敢的長臂猿) |
2007年10月18日 |
| 8.04 |
Hardy Heron(耐寒的蒼鷺) |
2008年4月24日(LTS) |
| 8.10 |
Intrepid Ibex (勇敢的野山羊) |
2008年10月30日 |
| 9.04 |
Jaunty Jackalope(得意洋洋的懷俄明野兔) |
2009年4月23日 |
| 9.10 |
Karmic Koala(幸運的考拉) |
2009年10月29日 |
| 10.04 |
Lucid Lynx(清醒的猞猁) |
2010年4月29日 |
| 11.10 |
Oneiric Ocelot(夢幻的豹貓) |
2010年10月13日 |
| 11.04 |
Natty Narwhal(敏捷的獨角鯨) |
2011年4月28日 |
| 12.04 |
Precise Pangolin(精准的穿山甲) |
2012年的4月26日(LTS) |
| 12.10 |
Quantal Quetzal(量子的綠咬鵑) |
2012年的10月20日 |
| 13.04 |
Raring Ringtail(鉚足了勁的貓熊) |
2013年4月25日 |
| 13.10 |
Saucy Salamander(活潑的蠑螈) |
2013年10月17日 |
| 14.04 |
Trusty Tahr (可靠的塔爾羊) |
2014年4月18日 (LTS) |
| 14.10 |
Utopic Unicorn(烏托邦獨角獸) |
2014年10月23日 |
| 15.04 |
Vivid Vervet (活潑的小猴) |
2015年4月 |
| 15.10 |
Wily Werewolf (狡猾的狼人) |
2015年10月 |
| 16.04 |
Xenial Xerus (好客的非洲地松鼠) |
2016年4月 (LTS) |
| 16.10 |
Yakkety Yak(氂牛) |
2016年10月 |
| 17.04 |
Zesty Zapus(開心的跳鼠) |
2017年4月 |
| 17.10 |
Artful Aardvark(機靈的土豚) |
2017年10月 |
| 18.04 |
Bionic Beaver(仿生海狸) |
2018年4月(LTS) |
| 18.10 |
Cosmic Cuttlefish (宇宙般大小的烏賊) |
2018年10月 |
| 19.04 |
Disco Dingo |
2019年4月 |
| 19.10 |
Eoan Ermine |
2019年10月 |
| ... |
... |
... |
這里以Ubuntu18.04為例
在網上找到阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
備份之前的源文件
sudo cp /etc/apt/souces.list /etc/apt/sources.list_bak
將新的源復制進去
sudo vim /etc/apt/sources.list
然后更新源文件
sudo apt-get update
更新軟件(如果是生產環境不要輕易更新軟件)
sudo apt-get upgtade
