windows使用msys2安装MinGW64
下载mysy2
官网下载非常慢,所以我们可以选择从清华大学的源下载:
- 清华大学的msys2源说明: https://mirrors.tuna.tsinghua.edu.cn/help/msys2
- 下载地址: https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/
在页面中找到最新的安装包,格式如下(个人喜欢压缩包,可以直接解压使用):
msys2-base-x86_64-XXXXXX.tar.xz
或者
msys2-x86_64-XXXXXX.exe
安装minGW64
tar.xz格式的安装包解压即可。
配置国内源(清华大学的源)
方式一
编辑 /etc/pacman.d/ 下的所有文件,把 https://mirror.msys2.org/ 替换为 https://mirrors.tuna.tsinghua.edu.cn/msys2/ 。
例如:修改 /etc/pacman.d/mirrorlist.mingw64,把https://mirror.msys2.org/mingw/x86_64/
修改为https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64/
方式二
直接运行如下命令即可:
1$ sed -i "s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g" /etc/pacman.d/mirrorlist*
更新源
1$ pacman -Syu
安装常用工具/命令
安装 c/c++ 开发环境
安装 c/c++
1$ pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake
建议将bin目录:${MINGW_HOME}\usr\bin 和 ${MINGW_HOME}\mingw64\bin 添加至环境变量(MINGW_HOME表示MinGW安装目录)
验证是否安装成功
1$ gcc --version
2gcc (Rev5, Built by MSYS2 project) 13.2.0
3Copyright (C) 2023 Free Software Foundation, Inc.
4This is free software; see the source for copying conditions. There is NO
5warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
6
7$ g++ --version
8g++ (Rev5, Built by MSYS2 project) 13.2.0
9Copyright (C) 2023 Free Software Foundation, Inc.
10This is free software; see the source for copying conditions. There is NO
11warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
看到以上内容则说明成功
安装其他常用工具
1# 安装 git、vim
2pacman -S git vim
评论