安装 MSYS2
安装 MSYS2
-
在 msys2.org 下载并安装 MSYS2。
-
打开 MSYS2 UCRT64。
-
安装 toolchain:
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain在 MSYS2 UCRT64 环境下安装的所有包都有
mingw-w64-ucrt-x86_64-(UCRT64)或mingw-w64-x86_64-(MSYS)前缀 -
设置 Path 环境变量:
Win-R运行SystemPropertiesAdvanced,将C:\msys64\ucrt64\bin和C:\msys64\usr\bin添加到系统Path环境变量。 -
验证安装。
在一个新的 PowerShell 会话中运行以下命令:
gcc --version
参考:Using GCC with MinGW | VS Code Docs
环境
MSYS2 提供了一些预设的环境,用于使用不同的编译工具链。其中 MSYS 是基础环境,其他环境均继承于 MSYS。最常用的环境是 UCRT64。
参考:
Windows Terminal
可以使用 Windows Terminal 启动 MSYS2。在 Windows Terminal 配置中加入以下条目:
"defaultProfile": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}", // 设置 UCRT64 为默认 shell
"profiles": {
"list": [
{
"guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}",
"name": "UCRT64 / MSYS2",
"commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -ucrt64 -shell bash",
"startingDirectory": "C:/msys64/home/%USERNAME%",
"icon": "C:/msys64/ucrt64.ico"
}
]
}
镜像
MSYS2 安装时一般已经配置好镜像源了,无需重复设置
在 MSYS2 UCRT64 环境中运行:
sed -i "s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g" /etc/pacman.d/mirrorlist*

浙公网安备 33010602011771号