First, download MSYS2 from the following direct link:
Run the installer and follow the installation instructions.
Open the MSYS2 terminal (the default terminal that comes with MSYS2). Run the following command to update the package database and base packages:
pacman -Syu
After the initial update, run the following command to update the rest of the base packages:
pacman -Su
Now, open the MSYS2 MinGW terminal (the blue one). Use the following commands based on your system's architecture:
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-i686-gcc
Similarly, to install the GDB debugger, use the following commands:
pacman -S mingw-w64-x86_64-gdb