linux 切换软件源到国内代理加速地址

简介: 经常会使用各种Linux的发行版本,很多时候需要使用yum和apt去安装软件,但是Linux镜像中的软件源使用的是国外的地址,访问速度非常慢,有些时候甚至访问失败,每次都需要去网上找对应的软件源地址。

一、背景


经常会使用各种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


目录
相关文章
|
5月前
|
JavaScript Linux Python
在Linux服务器中遇到的立即重启后的绑定错误:地址已被使用问题解决
总的来说,解决"地址已被使用"的问题需要理解Linux的网络资源管理机制,选择合适的套接字选项,以及合适的时间点进行服务重启。以上就是对“立即重启后的绑定错误:地址已被使用问题”的全面解答。希望可以帮你解决问题。
321 20
|
安全 Linux 应用服务中间件
在Linux中,包过滤防火墙与代理应用防火墙有什么区别?有哪些相应的产品?
在Linux中,包过滤防火墙与代理应用防火墙有什么区别?有哪些相应的产品?
|
9月前
|
负载均衡 Ubuntu 应用服务中间件
nginx修改网站默认根目录及发布(linux、centos、ubuntu)openEuler软件源repo站点
通过合理配置 Nginx,我们可以高效地管理和发布软件源,为用户提供稳定可靠的服务。
730 13
|
11月前
|
网络协议 Linux 开发工具
linux系统配置固定地址
linux系统配置固定地址
|
Linux 网络虚拟化 Windows
ccproxy windows上用的代理软件(类似linux系统上的squid)
ccproxy windows上用的代理软件(类似linux系统上的squid)
|
网络协议 Ubuntu Linux
会Linux系统上配IPv6地址的网工,那真是老6了!
会Linux系统上配IPv6地址的网工,那真是老6了!
310 0
|
安全 Linux 编译器
Linux进程——进程地址空间
Linux进程——进程地址空间
110 2
|
Linux
【Deepin 20系统】Linux系统修改MATLAB 打开默认地址(默认工作空间)
如何在Linux系统中修改MATLAB的默认打开地址(默认工作空间),通过编辑matlabrc.m文件来设置启动MATLAB时的初始目录。
274 0
|
存储 算法 Linux
【Linux】进程的地址空间
【Linux】进程的地址空间
114 2
|
Linux Shell
IP地址库Linux系统从APNIC获取地址库
IP地址库Linux系统从APNIC获取地址库
122 1

热门文章

最新文章