Skip to main content

GCC setup on Windows


Video

This material is also available in a video version, which can make the installation process much easier for you.


In this article, we will show you how to install one of the latest versions of the GCC compiler that will allow you to create programs in C++.

On Windows, the GCC compiler is part of the MSYS2 package. You can download it from this page:

https://msys2.org

Installation and setup

The steps described below are also on their main page.

1. Install MSYS2

Just click forward through their installer.

MSYS2 installer - path
Preview
Installation path

Remember to install msys2 in the disk space, that have no special characters or spaces in the path, preferably:

✔ Correct path
C:\msys64

or on another disk in a similar location.

2. Download appropriate packages

After installation, start the MSYS2 console through the start bar menu for the phrase MSYS2 MSYS.

Launching the MSYS2 console
Preview

Enter the following commands on it:

1. Updating the package database
pacman -Syu

When the following information appears in the console:

:: Proceed with installation? [Y/n]

Enter Y and accept with Return/Enter key.

Then type Y again when this information appears:

:: To complete this update all MSYS2 processes including this terminal will be closed. Confirm to proceed [Y/n]`

Please reopen the MSYS2 MSYS console

2. Base packages update
pacman -Su

Again, the question we confirm with Y:

:: Proceed with installation? [Y/n]

And we enter the command that will allow us to install MinGW-w64

3. Installing MinGW-w64 packages
pacman -S --needed base-devel mingw-w64-x86_64-toolchain

When the information pops up:

Enter a selection (default=all): 

Enter the numbers of the packages marked in green:

Selecting MinGW64 packages
Preview

In my case:

4. Installed package numbers
1 2 3 7 9 10 11 13 14 15 16 17 18 19
Alternatively

You can also install all packages by just pressing Enter, however, then it will take up a little more disk space.

3. Add path to system variable PATH

If you have followed the steps above correctly, you already have the GCC compiler installed on your computer.

To be able to use it efficiently, you also need to add the path to the msys64 \ mingw64 \ bin folder to the system environment variable named PATH.

If you chose the default installation path (C:\msys64), this path will look like this:

C:\msys64\mingw64\bin
Instruction

Read the following article to learn how to add a path to the environment variable PATH:

https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/

Test if it works

important

The next steps are optional.

Finally, it's a good idea to test if the compiler works.

Create an empty folder, e.g. on the desktop and create a file using a code editor or even Notepad, with the name and extension:

Main.cpp

Save the following code in it (you can copy from the site):

Main.cpp - C++20 support checking code
#include <iostream>
#include <ranges>
#include <algorithm>
#include <array>
namespace rg = std::ranges;

int main() {
auto arr = std::to_array({12, 8, 3, 7});

rg::sort(arr);
for (size_t i = 0; i < arr.size(); ++i)
{
if (i != 0) std::cout << ", ";
std::cout << arr[i];
}
}

Then run the console in the folder with the file Main.cpp, eg by using the shortcut Shift + PPM in the middle of the folder and pressing "Open the Powershell window here".

Enter the following command:

Compile & run command
g++ Main.cpp -std=c++20 && .\a

After a while, the following effect should appear in the console:

✔ Correct result
3, 7, 8, 13

Good luck with your programming 😀

Did everything go well?

If you have problems installing, please contact us on the Discord server on the #helpdesk channel:
https://discord.gg/xH2BPRNftS

GCC setup on Windows


Video

This material is also available in a video version, which can make the installation process much easier for you.


In this article, we will show you how to install one of the latest versions of the GCC compiler that will allow you to create programs in C++.

On Windows, the GCC compiler is part of the MSYS2 package. You can download it from this page:

https://msys2.org

Installation and setup

The steps described below are also on their main page.

1. Install MSYS2

Just click forward through their installer.

MSYS2 installer - path
Preview
Installation path

Remember to install msys2 in the disk space, that have no special characters or spaces in the path, preferably:

✔ Correct path
C:\msys64

or on another disk in a similar location.

2. Download appropriate packages

After installation, start the MSYS2 console through the start bar menu for the phrase MSYS2 MSYS.

Launching the MSYS2 console
Preview

Enter the following commands on it:

1. Updating the package database
pacman -Syu

When the following information appears in the console:

:: Proceed with installation? [Y/n]

Enter Y and accept with Return/Enter key.

Then type Y again when this information appears:

:: To complete this update all MSYS2 processes including this terminal will be closed. Confirm to proceed [Y/n]`

Please reopen the MSYS2 MSYS console

2. Base packages update
pacman -Su

Again, the question we confirm with Y:

:: Proceed with installation? [Y/n]

And we enter the command that will allow us to install MinGW-w64

3. Installing MinGW-w64 packages
pacman -S --needed base-devel mingw-w64-x86_64-toolchain

When the information pops up:

Enter a selection (default=all): 

Enter the numbers of the packages marked in green:

Selecting MinGW64 packages
Preview

In my case:

4. Installed package numbers
1 2 3 7 9 10 11 13 14 15 16 17 18 19
Alternatively

You can also install all packages by just pressing Enter, however, then it will take up a little more disk space.

3. Add path to system variable PATH

If you have followed the steps above correctly, you already have the GCC compiler installed on your computer.

To be able to use it efficiently, you also need to add the path to the msys64 \ mingw64 \ bin folder to the system environment variable named PATH.

If you chose the default installation path (C:\msys64), this path will look like this:

C:\msys64\mingw64\bin
Instruction

Read the following article to learn how to add a path to the environment variable PATH:

https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/

Test if it works

important

The next steps are optional.

Finally, it's a good idea to test if the compiler works.

Create an empty folder, e.g. on the desktop and create a file using a code editor or even Notepad, with the name and extension:

Main.cpp

Save the following code in it (you can copy from the site):

Main.cpp - C++20 support checking code
#include <iostream>
#include <ranges>
#include <algorithm>
#include <array>
namespace rg = std::ranges;

int main() {
auto arr = std::to_array({12, 8, 3, 7});

rg::sort(arr);
for (size_t i = 0; i < arr.size(); ++i)
{
if (i != 0) std::cout << ", ";
std::cout << arr[i];
}
}

Then run the console in the folder with the file Main.cpp, eg by using the shortcut Shift + PPM in the middle of the folder and pressing "Open the Powershell window here".

Enter the following command:

Compile & run command
g++ Main.cpp -std=c++20 && .\a

After a while, the following effect should appear in the console:

✔ Correct result
3, 7, 8, 13

Good luck with your programming 😀

Did everything go well?

If you have problems installing, please contact us on the Discord server on the #helpdesk channel:
https://discord.gg/xH2BPRNftS