linux 切换软件源到国内代理加速地址
一、背景
经常会使用各种Linux的发行版本,很多时候需要使用yum
和apt
去安装软件,但是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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 【非技术】说说2024年我都干了些啥