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.d
the directory under its installation path.
As you can see, each environment has an independent mirror configuration file, with a total of 7 files.
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
## Primary
The following two are the main servers of the official website.
## Tier 1
The following are the first-layer mirrors. These services have a bandwidth of 1GBit/s + and are synchronized at least once a day. The
## Tier 2
following 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 -Scc
clear cache and then pacman -Syu
update 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