How to switch mirror source in MSYS2 (with automatic modification by script)

This article will summarize [How to switch MSYS2 mirror]. It is actually relatively simple, but let’s record it.
The example below comes with a script so you don't have to manually modify each one.


1. Mirror service configuration file

All mirror service configurations of MSYS2 are in etc/pacman.dthe directory under its installation path.

Insert image description here
As you can see, each environment has an independent mirror configuration file, with a total of 7 files.

Insert image description here
As you can see, the image service domain names in different environments are the same, but the paths are different.

The first URL in these lists is the primary image, all other URLs will be used as fallbacks. You can make it the primary mirror by moving another mirror to the top

## PrimaryThe following two are the main servers of the official website.
## Tier 1The following are the first-layer mirrors. These services have a bandwidth of 1GBit/s + and are synchronized at least once a day. The
## Tier 2following are the second-layer mirrors. These services regularly synchronize with the main servers.

It is recommended to use the first layer of mirroring. Here we recommend Tsinghua University’s mirroring service.mirrors.tuna.tsinghua.edu.cn

The following example also uses Tsinghua's mirror service.

2. Modify the main image service configuration

There are 7 files to modify

I wrote a script here (the time it took to write the script was all done manually, this is to serve you, hahaha)

Just open a bash window of the environment and execute the following command to complete the modification.

cyl@DESKTOP-HE90P5G UCRT64 ~
$ cd /etc/pacman.d

cyl@DESKTOP-HE90P5G UCRT64 /etc/pacman.d
$ for file in mirrorlist.*; do wline=$(grep -n 'Primary' mirrorlist.msys | awk -F: '{print $1}'); wcontent=$(grep 'tsinghua' $file); sed -i "${wline}a ${wcontent}" $file; done

Verify whether the modification is successful

cyl@DESKTOP-HE90P5G UCRT64 /etc/pacman.d
$ head -n 6 mirrorlist.msys
# See https://www.msys2.org/dev/mirrors

## Primary
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch/
Server = https://mirror.msys2.org/msys/$arch/
Server = https://repo.msys2.org/msys/$arch/

Use pacman -Sccclear cache and then pacman -Syuupdate the software repository again.

cyl@DESKTOP-HE90P5G UCRT64 ~
$ pacman -Scc

Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove ALL files from cache? [Y/n] y
removing all files from cache...

Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] y
removing unused sync repositories...

cyl@DESKTOP-HE90P5G UCRT64 ~
$ pacman -Syu


Reference: Mirrors - MSYS2

おすすめ

転載: blog.csdn.net/B11050729/article/details/132747630