The background,

I often use a variety of Linux distributions, and most of the time I need to use YUM and APT to install software, but the software source in the Linux image uses a foreign address, so the access speed is very slow and sometimes even fails. Every time I need to go to the Internet to find the corresponding software source address.

This kind of work goes back and forth, SO I thought I would simply collect my common Linux distribution software source replacement methods at one time, and paste the command directly when necessary. Now I share this article, hoping to help friends who have such needs.

Centos replacement software source

Centos currently I mainly use Centos7, Centos8, the two versions of the replacement steps are basically the same, but there are some differences in the specific command, do not get confused.

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
Copy the code

Change the value to Aliyun

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
Copy the code

update

yum update
Copy the code

2.2 Centos8

Back up original software 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.backupCopy the code

All the above files need to be renamed, because centos-8. repo contains all the above files. If you change only centos-base. Repo file according to the traditional method, there will be a prompt

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 configurationCopy the code

Change the value to Aliyun

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

Run yum Makecache to generate the cache

yum clean all
yum makecache
Copy the code

Third, the Ubuntu

Ubuntu has many types of software source addresses. You need to write these types to /etc/apt/sources.list, and back them up before writing them.

Ubuntu 3.1 18

The following shows the backup command

cp  /etc/apt/sources.list /etc/apt/sources.list.bak
Copy the code

Write the long common aliyun 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
Copy the code

The following command is used to update the software source information

apt update
Copy the code

3.2 Ubuntu20

The following shows the backup command

cp  /etc/apt/sources.list /etc/apt/sources.list.bak
Copy the code

Write the long common aliyun 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
Copy the code

The following command is used to update the software source information

apt update
Copy the code

Debian needs to change the software source

The debian and Ubuntu replacements are basically the same, but the content is different, so don’t confuse the content.

4.1 the debian 10

The following shows the backup command

cp  /etc/apt/sources.list /etc/apt/sources.list.bak
Copy the code
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

Copy the code

The following command is used to update the software source information

apt update
Copy the code

4.2 the debian 9

The following shows the backup command

cp  /etc/apt/sources.list /etc/apt/sources.list.bak
Copy the code
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 EOFCopy the code

The following command is used to update the software source information

apt update
Copy the code

Five, the Mac OS

Mac OS system will generally use BREW to install software, but brew source is also in foreign countries, download software is always slow, here we can set some commonly used software warehouse is not Ali cloud mirror warehouse

5.1 BREW Replacement software source

The first thing to replace is the brew repository address itself, which you need to go to the Brew Git repository directory, as shown on the command line below

cd "$(brew --repo)"
Copy the code

After entering the Brew git repository directory, you need to change the remote address to the aliyun repository address, as shown below

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

Then you need to replace the homebrew-core repository address by entering the repository directory, as shown below

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

After entering the Homebrew-core repository, you need to replace the remote repository address as shown in the following command

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

After the addresses of both repositories have been replaced, brew needs to take effect, as shown below

brew update
Copy the code

Author: Tang Qingsong

Date: September 16, 2021

WeChat: songboy8888