【服务器工具】Linux系统替换软件源-LinuxMirrors一键换源脚本

13,879
IPRoyal

通常我们新开一台服务器,首先要做的都是把系统软件源更新一遍、或安装些必要的命令,避免在部署服务时找不到命令,但有时候在更新软件源时网速很慢或找不到一些命令包,这个时候就需要给系统更换下镜像源,考虑到Linux有多个发行版系统,这里采用LinuxMirrors一键更换国内源脚本,适配多个GNU/Linux 发行版,理论支持所有系统架构。

【服务器工具】Linux系统替换软件源-LinuxMirrors一键换源脚本

Linux通过一键脚本换源

1、GNU/Linux 一键更换国内软件源脚本命令:文章源自技术白-https://jishubai.com/316.html

##国内网络
bash <(curl -sSL https://linuxmirrors.cn/main.sh)

##海外网络
bash <(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh) --abroad
或
wget https://linuxmirrors.cn/main.sh && chmod +x main.sh && ./main.sh

2、如果提示curl或wget不存在,以root权限或root用户执行下列命令安装:文章源自技术白-https://jishubai.com/316.html

##安装curl
yum install -y curl || apt-get install -y curl
##安装wget
yum install -y wget || apt-get install -y wget

3、执行脚本后进入到菜单选择所需的软件源,然后根据提示一步步操作即可;文章源自技术白-https://jishubai.com/316.html

【服务器工具】Linux系统替换软件源-LinuxMirrors一键换源脚本

Linux手动换源

Debian换源方法:命令行输入 nano /etc/apt/sources.list 编辑文件,删除该文件所有内容,然后复制粘贴以下内容;文章源自技术白-https://jishubai.com/316.html

华为源:文章源自技术白-https://jishubai.com/316.html

deb https://mirrors.huaweicloud.com/debian/ buster main contrib non-free
deb https://mirrors.huaweicloud.com/debian/ buster-updates main contrib non-free
deb https://mirrors.huaweicloud.com/debian/ buster-backports main contrib non-free
deb https://mirrors.huaweicloud.com/debian-security/ buster/updates main contrib non-free

deb-src https://mirrors.huaweicloud.com/debian/ buster main contrib non-free
deb-src https://mirrors.huaweicloud.com/debian/ buster-updates main contrib non-free
deb-src https://mirrors.huaweicloud.com/debian/ buster-backports main contrib non-free 

Debian 官方全球镜像站列表地址:https://www.debian.org/mirror/list文章源自技术白-https://jishubai.com/316.html

快速换源:直接在命令行复制粘贴如下代码(linode源)文章源自技术白-https://jishubai.com/316.html

cat > /etc/apt/sources.list << EOF
deb http://mirrors.linode.com/debian/ bullseye main contrib non-free
deb-src http://mirrors.linode.com/debian/ bullseye main contrib non-free

deb http://mirrors.linode.com/debian/ bullseye-updates main contrib non-free
deb-src http://mirrors.linode.com/debian/ bullseye-updates main contrib non-free

deb http://mirrors.linode.com/debian/ bullseye-backports main contrib non-free
deb-src http://mirrors.linode.com/debian/ bullseye-backports main contrib non-free

deb http://mirrors.linode.com/debian-security/ bullseye-security main contrib non-free
deb-src http://mirrors.linode.com/debian-security/ bullseye-security main contrib non-free
EOF

以上两个换源方法弄好后,都需要执行下列命令更新:文章源自技术白-https://jishubai.com/316.html

apt-get update -y && apt-get install curl -y

Ubuntu换源方法:命令行输入 nano /etc/apt/sources.list 编辑文件,删除该文件所有内容,然后复制粘贴以下内容;文章源自技术白-https://jishubai.com/316.html

阿里源:文章源自技术白-https://jishubai.com/316.html

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse 
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb 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 main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse focal

修改好后,执行下列命令更新:

apt-get update -y && apt-get install curl -y

Centos7换源方法:命令行输入 vi /etc/yum.repos.d/CentOS-Base.repo 编辑文件,删除该文件所有内容,然后复制粘贴以下内容,官方源无需编辑直接执行命令即可;

阿里源:

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

官方源:

cd /etc/yum.repos.d/
rm -rf CentOS-*
rpm -Uvh --force http://mirror.centos.org/centos-7/7.9.2009/os/x86_64/Packages/centos-release-7-9.2009.0.el7.centos.x86_64.rpm
yum clean all
yum makecache
yum update -y

修改好后,执行下列命令更新:

yum update -y && yum install curl -y

Centos8换源方法:直接执行命令即可;

官方源:

cd /etc/yum.repos.d/
rm -rf CentOS-*
rpm -Uvh --force http://mirror.centos.org/centos-8/8/BaseOS/x86_64/os/Packages/centos-linux-release-8.3-1.2011.el8.noarch.rpm
yum clean all
yum makecache
yum update -y

修改好后,执行下列命令更新:

yum update -y && yum install curl -y

本站TG群组skill_blog   联系博主:nbskill (微信协助) 杂货铺曙光商店

IPRoyal
 最后更新:2023-8-12
技术白
  • LinuxMirrors一键换源脚本
  • centos换软件源
  • debian换软件源
  • ubuntu换软件源
  • linux更新软件源命令
  • linux换源脚本
  • Linux手动换源