Linux switches software source to domestic agent acceleration address

Time:2022-5-4

1、 Background

I often use various Linux distributions and need to use them many timesyumandaptTo install the software, but the software source in the Linux image uses the foreign address, and the access speed is very slow. Sometimes the access fails. You need to find the corresponding software source address on the Internet every time.

This kind of work is repeated again and again. I want to simply collect the software source replacement methods of my commonly used Linux distribution versions at one time, and paste the commands directly when necessary. Now share this article, hoping to help friends with such needs.

2、 CentOS replacement software source

At present, I mainly use CentOS 7 and CentOS 8. The replacement steps of the two versions are basically the same, but there are some differences in specific commands. Don’t confuse them.

2.1 Centos7

Install the base reop source, and then back up the old configuration files

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

Modify to Alibaba cloud

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

to update

yum update

2.2 Centos8

Back up the original software source files

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

All the above documents need to be renamed because Ali YunyuanCentos-8.repoAll the above documents are included. If you follow the traditional method, only change themCentOS-Base.repoA prompt will appear in this file

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

Modify to Alibaba cloud

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

Run Yum makecache to generate a cache

yum clean all
yum makecache

3、 Ubuntu

There are many types of software source addresses for Ubuntu, which need to be written to/etc/apt/sources.listIn the file, it is best to back it up before writing.

3.1 Ubuntu 18

The backup command is as follows

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

Write the common alicloud software source address to the file. The command is as follows:

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

The commands for updating software source information are as follows:

apt update

3.2 Ubuntu20

The backup command is as follows

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

Write the common alicloud software source address to the file. The command is as follows:

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

The commands for updating software source information are as follows:

apt update

4、 Debian needs to change the software source

The replacement methods of Debian system and Ubuntu are basically the same, but the contents are different. Don’t confuse the contents.

4.1 debian 10

The backup command is as follows

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

The commands for updating software source information are as follows:

apt update

4.2 debian 9

The backup command is as follows

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

The commands for updating software source information are as follows:

apt update

5、 Mac OS

Mac OS systems generally use brew to install software, but the source of brew is also abroad. Downloading software is always slow. Here, we can set some commonly used software warehouses without alicloud image warehouses

5.1 brew replacement software source

The first thing to replace is the warehouse address of brew itself. Here, you need to enter the GIT warehouse directory of brew. The command line is as follows

cd "$(brew --repo)"

After entering the GIT warehouse directory of brew, you need to change the remote address to the warehouse address of Alibaba cloud. The command is as follows:

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

Next, you need to replace the warehouse address of homebrew core. You also need to enter the directory of this warehouse first. The command is as follows

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

get intohomebrew-coreAfter the warehouse, you need to replace the remote warehouse address. The command is as follows

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

After the addresses of the two warehouses are replaced, brew needs to take effect. The command is as follows

brew update

Author: Tang Qingsong

Date: September 16, 2021

Wechat: songboy8888

This work adoptsCC agreement, reprint must indicate the author and the link to this article