5

1. Background

Various Linux distributions are often used. In many cases, you need to use yum and apt to install software, but the software source in the Linux mirror uses a foreign address, and the access speed is very slow, sometimes even the access fails, and you need it every time Go to the Internet to find the corresponding software source address.

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

Two, Centos replacement software source

At present, I mainly use centos7 and centos8. The replacement steps of the two versions are basically the same, but there are some differences in the specific commands, so don't confuse them.

2.1 Centos7

Install the base reop source, then back up the old configuration file

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

Modified 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

renew

yum update

2.2 Centos8

Back up 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

The above files need to be renamed, because the Centos-8.repo in Aliyun source contains all the above files. If you only change CentOS-Base.repo according to the traditional method, a prompt will appear

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

Modified 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 cache

yum clean all
yum makecache

Three, Ubuntu

There are many types of Ubuntu software source addresses. These types need to be written into the /etc/apt/sources.list file. It is best to back them 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 long and common Alibaba Cloud 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 command to update software source information is 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 long and common Alibaba Cloud 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 command to update software source information is as follows

apt update

Fourth, debian needs to change the software source

The debian system and Ubuntu replacement methods are basically the same, but the content is different, the content should not be confused.

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 command to update software source information is 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 command to update software source information is as follows

apt update

Five, Mac os

Mac OS systems generally use brew to install software, but the source of brew is also abroad, and downloading software is always slow. Here we can set some commonly used software warehouses to mirror warehouses of Aliyun

5.1 brew replacement software source

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

cd "$(brew --repo)"

After entering brew's git warehouse directory, you need to modify the remote address to the Alibaba Cloud warehouse address. The command is as follows

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

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

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

After entering the homebrew-core 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


汤青松
5.2k 声望8.3k 粉丝

《PHP Web安全开发实战》 作者