天天看點

Linux系統各發行版換國内yum或apt源,加速軟體下載下傳更新

Centos、Ubuntu、Debian、Fedora、OpenSUSE、FreeBSD系統換軟體源

Linux系統安裝完後軟體源一般都是國外伺服器,在國内特别慢,這時候就需要更換國内的鏡像源。

高成本效益和便宜的VPS/雲伺服器推薦:

https://blog.zeruns.tech/archives/383.html

Centos

1、備份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup           

2、更換源

下載下傳新的

CentOS-Base.repo

/etc/yum.repos.d/

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo           

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo           

注意

http://mirrors.aliyun.com/repo/Centos-7.repo

中的

7

改為自己的Centos版本号,比如Centos 8就是

http://mirrors.aliyun.com/repo/Centos-8.repo

3、運作yum makecache生成緩存

yum makecache           

Ubuntu

1.備份

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

将以前的源備份一下,以防以後可以用的。

2.更改檔案權限使其可編輯

sudo  chmod  777  /etc/apt/source.list           

3.更換源

sudo nano /etc/apt/sources.list           

使用nano打開文本,删除原來檔案裡的内容,将下面其中一個源複制進去,然後儲存。

阿裡源:

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse           

清華源:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse           

3.更新

更新源

sudo apt-get update           

修複損壞的軟體包,嘗試解除安裝出錯的包,重新安裝正确版本的。

sudo apt-get -f install           

更新軟體

sudo apt-get upgrade           

Debian

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

2.更換源

一般情況下,将

/etc/apt/sources.list

檔案中 Debian 預設的源位址

http://deb.debian.org

替換為

http://mirrors.ustc.edu.cn

(清華源)即可。

sudo sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list           

也可以直接編輯

/etc/apt/sources.list

檔案(v)

sudo vi /etc/apt/sources.list           

加入如下内容即可

deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable main contrib non-free
deb http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free

# deb http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free           

敲擊

i

鍵進入插入模式,組合鍵

ctrl+shift+v

将複制内容粘貼至源檔案中,敲擊esc鍵進入指令模式,輸入

:wq!

儲存并退出。

其他鏡像源:

阿裡雲:

http://mirrors.aliyun.com/

搜狐:

http://mirrors.sohu.com/

網易:

http://mirrors.163.com/

sudo apt-get update           

Fedora

su
cd /etc/yum.repos.d/
mv fedora.repo fedora.repo.backup
mv fedora-updates.repo fedora-updates.repo.backup
wget -O /etc/yum.repos.d/fedora.repo http://mirrors.aliyun.com/repo/fedora.repo
wget -O /etc/yum.repos.d/fedora-updates.repo http://mirrors.aliyun.com/repo/fedora-updates.repo
dnf clean all
dnf makecache           

OpenSUSE

1.禁用原有軟體源

sudo zypper mr -da           

2.添加科大鏡像源

sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/distribution/leap/42.1/repo/oss USTC:42.1:OSS
sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/distribution/leap/42.1/repo/non-oss USTC:42.1:NON-OSS
sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/update/leap/42.1/oss USTC:42.1:UPDATE-OSS
sudo zypper ar -fc https://mirrors.ustc.edu.cn/opensuse/update/leap/42.1/non-oss USTC:42.1:UPDATE-NON-OSS           

3.手動重新整理軟體源

sudo zypper ref           

4.更新系統

sudo zypper up           

FreeBSD

1.修改 pkg 源

mkdir -p /usr/local/etc/pkg/repos
vim /usr/local/etc/pkg/repos/FreeBSD.conf

# content of FreeBSD.conf
FreeBSD: {
    url: "pkg+http://mirrors.ustc.edu.cn/freebsd-pkg/${ABI}/quarterly",
}           

2.修改 ports 源

vim /etc/make.conf

# content of make.conf
FETCH_CMD=axel -n 10 -a
DISABLE_SIZE=yes
MASTER_SITE_OVERRIDE?=http://mirrors.ustc.edu.cn/freebsd-ports/distfiles/${DIST_SUBDIR}/           

3.修改 portsnap 源

vim /etc/portsnap.conf

# content of porsnap.conf
SERVERNAME=porsnap.tw.freebsd.org           

推薦文章:

搭建内網穿透伺服器,帶Web面闆:

https://blog.zeruns.tech/archives/397.html

怎樣搭建個人部落格:

https://blog.zeruns.tech/archives/218.html

CentOS 7安裝新核心并啟用Google BBR教程:

https://blog.zeruns.tech/archives/39.html

vultr $2.5 純ipv6伺服器+CDN搭建同時支援ipv4和ipv6的網站:

https://blog.zeruns.tech/archives/345.html

搭建AdGuard Home無廣告及跟蹤的DNS解析伺服器:

https://blog.zeruns.tech/archives/318.html

繼續閱讀