关于linux:linux-切换软件源到国内代理加速地址

38次阅读

共计 5492 个字符,预计需要花费 14 分钟才能阅读完成。

一、背景

常常会应用各种 Linux 的发行版本,很多时候须要应用 yumapt去装置软件,然而 Linux 镜像中的软件源应用的是国外的地址,访问速度十分慢,有些时候甚至拜访失败,每次都须要去网上找对应的软件源地址。

这种工作反反复复,我想着罗唆一次性收集我罕用的 Linux 发行版本的软件源替换办法,须要的时候间接将命令粘贴下来就能够了,当初将这个文章分享进去,心愿能帮到有此类需要的敌人。

二、Centos 替换软件源

centos 目前我次要是应用的是 centos7、centos8,两个版本替换步骤根本是统一的,然而具体命令有一些区别,千万不要搞混了。

2.1 Centos7

装置 base reop 源,接着备份旧的配置文件

sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

批改为阿里云

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

更新

yum update

2.2 Centos8

备份原始软件源文件

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
mv /etc/yum.repos.d/CentOS-PowerTools.repo /etc/yum.repos.d/CentOS-PowerTools.repo.backup
mv /etc/yum.repos.d/CentOS-Extras.repo.backup /etc/yum.repos.d/CentOS-Extras.repo.backup.backup
mv /etc/yum.repos.d/CentOS-centosplus.repo.repo /etc/yum.repos.d/CentOS-centosplus.repo.backup
mv /etc/yum.repos.d/CentOS-AppStream.repo.repo /etc/yum.repos.d/CentOS-AppStream.repo.backup

以上文件都须要重新命名,因为阿里云源里 Centos-8.repo 蕴含了上述所有文件,如果依照传统手法只更改 CentOS-Base.repo 这个文件 会呈现一下提醒

Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration

批改为阿里云

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

运行 yum makecache 生成缓存

yum clean all
yum makecache

三、Ubuntu

Ubuntu 的软件源地址有很多种类型,须要将这些类型写入到 /etc/apt/sources.list 文件中,写入之前最好将其备份。

3.1 Ubuntu 18

备份命令如下所示

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

将长常见的阿里云软件源地址写入到文件,命令如下所示

tee /etc/apt/sources.list <<-'EOF'
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
EOF

更新软件源信息命令如下所示

apt update

3.2 Ubuntu20

备份命令如下所示

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

将长常见的阿里云软件源地址写入到文件,命令如下所示

tee /etc/apt/sources.list <<-'EOF'
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
EOF

更新软件源信息命令如下所示

apt update

四、debian 需改软件源

debian 零碎和 Ubuntu 替换办法根本是统一的,然而内容不一样,内容不要搞混同。

4.1 debian 10

备份命令如下所示

cp  /etc/apt/sources.list /etc/apt/sources.list.bak
tee /etc/apt/sources.list <<-'EOF'
deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ buster/updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian-security/ buster/updates main non-free contrib
EOF

更新软件源信息命令如下所示

apt update

4.2 debian 9

备份命令如下所示

cp  /etc/apt/sources.list /etc/apt/sources.list.bak
tee /etc/apt/sources.list <<-'EOF'
deb http://mirrors.aliyun.com/debian stretch main contrib non-free
deb-src http://mirrors.aliyun.com/debian stretch main contrib non-free
deb http://mirrors.aliyun.com/debian stretch-updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian stretch-updates main contrib non-free
deb http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free
deb-src http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free
EOF

更新软件源信息命令如下所示

apt update

五、Mac os

Mac OS 零碎个别都会应用 brew 来装置软件,然而 brew 的源也是在国外,下载软件总是很慢,这里咱们能够将一些罕用的软件仓库设置未阿里云的镜像仓库

5.1 brew 替换软件源

首先要替换的是 brew 自身的仓库地址,这里须要进入到 brew 的 git 仓库目录去,命令行如下所示

cd "$(brew --repo)"

进入到 brew 的 git 仓库目录后,须要将近程地址批改为阿里云的仓库地址,命令如下所示

git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

接下来须要替换 homebrew-core 的仓库地址,同样须要先进入此仓库的目录,命令如下所示

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"

进入 homebrew-core 仓库之后,须要替换近程仓库地址,命令如下所示

git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

两个仓库的地址都替换实现之后,须要让 brew 失效,命令如下所示

brew update

作者:汤青松

日期:2021 年 9 月 16 日

微信:songboy8888

正文完
 0