How to Install C and C++ Compilers on Windows (2024)

If you want to run C or C++ programs in your Windows operating system, then you need to have the right compilers.

The MinGW compiler is a well known and widely used software for installing GCC and G++ compilers for the C and C++ programming languages.

But many devs face difficulties when installing the compiler, so I am going to show you all the steps to do so in this article with screenshots to help you get it done.

I will be using Windows 11, but the same process is applicable for all other Windows operating systems unless you are using Windows XP (You need to change some steps in Windows XP).

If you'd like to watch the video I made on this topic as well, here it is:

Install MSYS2

Firstly we need to download an executable file from MSYS2. Go to the official website of MSYS2: https://www.msys2.org/. The website looks like below as of today.

How to Install C and C++ Compilers on Windows (1)

Scroll down a little bit until you find the download button for the executable file.

How to Install C and C++ Compilers on Windows (2)

Simply click on the installer button and save the installer file in any place you want.

How to Install C and C++ Compilers on Windows (3)

Finish downloading the executable file. It should not take much time depending on your internet speed.

How to Install C and C++ Compilers on Windows (4)

After downloading the file, we will get this executable file.

How to Install C and C++ Compilers on Windows (5)

Double click on the executable file. Then click Next.

How to Install C and C++ Compilers on Windows (6)

Keep the name as it is, and click Next.

How to Install C and C++ Compilers on Windows (7)

Keep all this as it is, and click Next.

How to Install C and C++ Compilers on Windows (8)

Give it some time to finish the installation process.

How to Install C and C++ Compilers on Windows (9)

If you keep the checkmark, then the MSYS2 terminal will open once you click Finish.

How to Install C and C++ Compilers on Windows (10)

I prefer to do it this way, but if you want to do the remaining tasks later, then you need to open the terminal by yourself from the start menu.

In that case, you have to click the start button > Search for MSYS2 and click on the terminal like in the following picture:

How to Install C and C++ Compilers on Windows (11)

Let me assume that we have opened the MSYS2 MSYS terminal successfully.

Apply the command pacman -Syu to update the package database and the base packages.

How to Install C and C++ Compilers on Windows (12)

Type Y and press the enter key if you get this type of installation prompt.

How to Install C and C++ Compilers on Windows (13)
How to Install C and C++ Compilers on Windows (14)
How to Install C and C++ Compilers on Windows (15)

Type Y and press the enter key.

How to Install C and C++ Compilers on Windows (16)
How to Install C and C++ Compilers on Windows (17)

The terminal will be closed. We have to open the terminal manually and update the rest of the packages.

Click the start button.

How to Install C and C++ Compilers on Windows (18)

Search the folder named MSYS2 64bit. Click on the folder to expand and get the terminal. Open the terminal by clicking MSYS2 MSYS.

How to Install C and C++ Compilers on Windows (19)

Update the rest of the packages by applying the command, pacman -Su. You might need to apply the command pacman -Sy if the terminal tells you to do that.

How to Install C and C++ Compilers on Windows (20)

If you get any installation prompt, then you need to type Y or y and press the enter key.

How to Install C and C++ Compilers on Windows (21)
How to Install C and C++ Compilers on Windows (22)

Wait a little to finish the installation.

How to Install C and C++ Compilers on Windows (23)
How to Install C and C++ Compilers on Windows (24)

Close the window after finishing the installation.

Install the GCC and G++ Compilers

Click the start button. Find the MSYS2 64bit folder. Click on that folder to expand it.

How to Install C and C++ Compilers on Windows (25)

If you are using a 64 bit operating system like I am, then we need to use the MSYS2 MinGW x64 terminal. Click on the terminal to open that.

How to Install C and C++ Compilers on Windows (26)

⚠️ But, if you are using a 32 bit operating system, then you have to use the MSYS2 MinGW x86 terminal. Then, you need to open that terminal.

How to Install C and C++ Compilers on Windows (27)

As I am using a 64 bit operating system, I have opened the terminal for 64 bit. Apply the command pacman -S mingw-w64-x86_64-gcc to install the compilers.

⚠️ If you are using a 32 bit operating system, then you have to apply the command pacman -S mingw-w64-i686-gcc in your 32 bit terminal.

How to Install C and C++ Compilers on Windows (28)

Wait for a little while.

How to Install C and C++ Compilers on Windows (29)

Type Y or y and press the enter key if you get the installation prompts.

How to Install C and C++ Compilers on Windows (30)
How to Install C and C++ Compilers on Windows (31)

Give it some time to finish the installation process.

How to Install C and C++ Compilers on Windows (32)
How to Install C and C++ Compilers on Windows (33)

You've now finished installing the compilers.

How to Install the Debugger

If you are using a 64 bit operating system like I am, then you have to apply the command pacman -S mingw-w64-x86_64-gdb.

⚠️ If you are using a 32 bit operating system, then you have to apply the command pacman -S mingw-w64-i686-gdb in your 32 bit terminal.

How to Install C and C++ Compilers on Windows (34)

If you get any installation prompt, then simply type Y or y and press the enter key.

How to Install C and C++ Compilers on Windows (35)
How to Install C and C++ Compilers on Windows (36)

Give it some time to finish the installation.

How to Install C and C++ Compilers on Windows (37)
How to Install C and C++ Compilers on Windows (38)

You can close the terminal.

How to Add the Directory to the Path of the Environment Variables

Open the file explorer.

How to Install C and C++ Compilers on Windows (39)

I am assuming that you have installed the MSYS into the default directory like I have. If you used custom directories, then you need to go to the directory where you installed it.

How to Install C and C++ Compilers on Windows (40)

If you are using a 64 bit operating system like I am, then go to the mingw64 folder.

⚠️ If you are using a 32 bit operating system, then go to the mingw32 folder.

How to Install C and C++ Compilers on Windows (41)

We have to go to the binary folder now. Go to the bin folder.

How to Install C and C++ Compilers on Windows (42)

⚠️ If you are using a 32 bit operating system, then you have to go into your mingw32 folder > bin folder.

Copy the directory.

How to Install C and C++ Compilers on Windows (43)

⚠️ If you are using a 32 bit operating system, and you also installed the MSYS2 in the default directory, then your directory should be like the following:

C:\msys64\mingw32\bin

Open the Advanced System Settings. You can do that in many ways. A simple way is to simply click the start button and search for it like the below screenshot.

How to Install C and C++ Compilers on Windows (44)

Click Environment Variables from the Advanced tab.

How to Install C and C++ Compilers on Windows (45)

Click on Path and select that. Then click Edit.

How to Install C and C++ Compilers on Windows (46)

A window will appear as below:

How to Install C and C++ Compilers on Windows (47)

Click New.

How to Install C and C++ Compilers on Windows (48)

A blank box will appear.

How to Install C and C++ Compilers on Windows (49)

Paste the directory here.

How to Install C and C++ Compilers on Windows (50)
How to Install C and C++ Compilers on Windows (51)

Click OK.

How to Install C and C++ Compilers on Windows (52)

Click OK.

How to Install C and C++ Compilers on Windows (53)

Click OK.

How to Install C and C++ Compilers on Windows (54)

If you want to get all the steps in a video, then you can watch this video as well.

Check the Install

Now it is time to check whether we have successfully installed all of the above or not.

Open the terminal / PowerShell / CMD and apply the commands serially:

For checking the GCC version:

gcc --version
How to Install C and C++ Compilers on Windows (55)

For checking the G++ version:

g++ --version
How to Install C and C++ Compilers on Windows (56)

For checking the GDB version:

gdb --version
How to Install C and C++ Compilers on Windows (57)

Conclusion

I hope this article helps you install your compilers on the Windows operating system for C and C++ programs.

Thanks for reading the entire article. If it helps you then you can also check out other articles of mine at freeCodeCamp.

If you want to get in touch with me, then you can do so using Twitter, LinkedIn, and GitHub.

You can also SUBSCRIBE to my YouTube channel (Code With FahimFBA) if you want to learn various kinds of programming languages with a lot of practical examples regularly.

If you want to check out my highlights, then you can do so at my Polywork timeline.

You can also visit my website to learn more about me and what I'm working on.

Thanks a bunch!

How to Install C and C++ Compilers on Windows (2024)
Top Articles
Latest Posts
Article information

Author: Fredrick Kertzmann

Last Updated:

Views: 5596

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Fredrick Kertzmann

Birthday: 2000-04-29

Address: Apt. 203 613 Huels Gateway, Ralphtown, LA 40204

Phone: +2135150832870

Job: Regional Design Producer

Hobby: Nordic skating, Lacemaking, Mountain biking, Rowing, Gardening, Water sports, role-playing games

Introduction: My name is Fredrick Kertzmann, I am a gleaming, encouraging, inexpensive, thankful, tender, quaint, precious person who loves writing and wants to share my knowledge and understanding with you.