MinGW and MSYS2 Installation

1. What are MinGW and MSYS2

MinGW is the abbreviation of “Minimalist GNU for Windows”, which contains a lot of develop tools. Now we often use the MinGW-64 version. If we need to compile some C/C++ files, the MinGW has what we need.

However, install MinGW is a little cumbersome, the more common way is install MSYS2.

The MSYS2 is the abbreviation of “Minimal SYStem 2”. It is a “micro Linux-like develop environment”, which contains many Linux tools includes bash, ls, grep, sed, awk, find, make, git…

1.1 Why do we install MSYS2 instead of MinGW directly?

After installing the MSYS2, we get a magnificent advantage: the pacman(Package Manager).

e.g. The traditional way to install the GCC:

  • Step1. download the compressed file(zip or tar file…)
  • Step2. decompress the file.
  • Step3. configure the PATH

If you need to update your GCC, you need to redownload the file and cover it .

But if you use the pacman, you just need one command to finish the installation:

pacman -S mingw-w64-ucrt-x86_64-gcc

1.2 Summary

So let’s conclude the COT:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
We need to compile C/C++ files

We need a C/C++ compiler

MinGW-w64 provides GCC/G++ compilers for Windows

We need to install a MinGW-w64 toolchain

There are several ways to install MinGW-w64

The recommended way is to install MSYS2

MSYS2 provides the pacman package manager

Use pacman to install the MinGW-w64 toolchain

Use gcc/g++ to compile C/C++ files

2. Install MSYS2

Download MSYS2.

After installing this, run this command to install gcc and gdb in the UCRT64 window:

1
pacman -S mingw-w64-ucrt-x86_64-gcc
1
pacman -S mingw-w64-ucrt-x86_64-gdb

Check:

1
2
3
4
5
6
7
test@ѩ▒ UCRT64 ~
$ gcc --version
gcc.exe (Rev5, Built by MSYS2 project) 16.1.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

1
2
3
4
5
6
7
8
test@ѩ▒ UCRT64 ~
$ gdb --version
GNU gdb (GDB) 17.2
Copyright (C) 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

check in the git bash:

1
2
3
test@▒ѩ▒ MINGW64 ~
$ gcc --version
bash: gcc: command not found

the gcc command is not found, so we need to add the PATH.

find the MSYS2’s urt64’s bin folder path:

D:\softwares\MSYS2\ucrt64\bin

add it to the Windows’ Environment Variable PATH.

Then restart the git bash window, check:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
test@ѩ▒ MINGW64 ~
$ g++ --version
g++.exe (Rev5, Built by MSYS2 project) 16.1.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


test@ѩ▒ MINGW64 ~
$ gcc --version
gcc.exe (Rev5, Built by MSYS2 project) 16.1.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


test@ѩ▒ MINGW64 ~
$ gdb --version
GNU gdb (GDB) 17.2
Copyright (C) 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

3. Configure VS Code

3.1 Choose the default compiler for c/cpp

Open the VS Code, find the gear at the left-bottom. Click and choose the settings, then search C_Cpp.default.compilerPath. Open the setting.json, and fulfill the value:

1
"C_Cpp.default.compilerPath": ""
1
"C_Cpp.default.compilerPath": "D:/softwares/MSYS2/ucrt64/bin/gcc.exe"

3.2 Create task.json and launch.json file

Create a new folder and open it in vscode:

E:\test_msys2_c

then press Ctrl+Shift+P search for :Tasks: Configure Default Build Task, select: Create tasks.json file from template, select: Others, create tasks.json file.

Amend the json file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": false
},
"problemMatcher": [
"$gcc"
],
"detail": "Generated task by VSCode"
},
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "D:/softwares/MSYS2/ucrt64/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:/softwares/MSYS2/ucrt64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}

Note: I set the git bash as the default terminal for vscode, so I change this part:

1
2
3
4
5
6
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
]

into:

1
2
3
4
5
6
"args": [
"-g",
"\"${file}\"",
"-o",
"\"${fileDirname}/${fileBasenameNoExtension}.exe\""
]

Press Ctrl+Shift+D search for :create a launch.json file, select: C++ (GDB/LLDB), create launch.json file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:/softwares/MSYS2/ucrt64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}

3.3 Test

create a hello.c file in the last folder:

1
2
3
4
5
6
#include <stdio.h>

int main() {
printf("Hello, World!\n");
return 0;
}