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

1.備份

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/

3.更新

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章