Knowledgebase

How to Install GCC Compiler on Windows?

Introduction

This knowledge base is for those planning to install the GCC (GNU Compiler Collection) compiler on their Windows systems. Whether you are a programming beginner or an experienced developer, having GCC installed on your Windows system is crucial. It is an essential platform for compiling and running C, C++, and other language programs seamlessly.

It is important to note that since GCC was originally designed for Unix-based systems, installing it on Windows requires some additional steps.

This knowledge base will walk you through the step-by-step process of installing GCC on Windows using MinGW-w64 and other alternative methods.

By the end of this blog, you will understand:

  •  What is GCC Compiler?
  •  What are its Prerequisites?
  •  What are the Features of GCC Compiler?
  •  Steps to Install GCC Using MinGW-w64
  •  Installing GCC on Windows via Subsystem for Linux (WSL)

Let’s dive in and set up a fully functional GCC Compiler on Windows that is ready for development.

What is a GCC Compiler?

GCC (GNU Compiler Collection) is a powerful tool for transforming human-readable code written in languages like C, C++, and Fortran into machine-readable instructions that a computer can understand and execute. It acts as a translator between the programmer and the computer.

Why is GCC Important?

  • It allows developers to compile and run their programs.
  • It supports multiple programming languages.
  • It is widely used in software development, operating systems, and embedded systems.


Also Read: A Guide To Locating & Editing a Host File in Windows 10


Example: Compiling a Simple C Program with GCC

Let’s say you write a simple C program called hello.c that prints “Hello, World!”

Step 1: Write the C Code

c

#include <stdio.h>

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

Step 2: Compile the Code Using GCC

➔ If you have GCC installed, open the command prompt and run:

nginx

gcc hello.c -o hello.exe

Here’s what happens:

  • gcc → Calls the GCC compiler.
  • hello.c → The source file to be compiled.
  • -o hello.exe → Specifies the output file name (hello.exe).

Step 3: Run the Compiled Program

Input:

hello.exe

Output:

Hello, World!

This simple example shows how GCC compiles a human-written C program into an executable file that the computer can run.


Also Read: What is Telnet Command in Windows & How to Use it?


What are its Prerequisites?

Before installing the GCC compiler on your Windows system, check a few things. Here are the prerequisites necessary for a smooth installation process and to help avoid errors.

1. A Windows Operating System

You need a Windows PC (Windows 10, 11, or earlier versions). The installation steps may differ slightly based on your version of Windows.

2. Administrator Access

To install software, you may require administrator privileges. If you are using a personal computer, you likely have the necessary permissions. However, if you are on a work or school computer, you should obtain approval for admin access.

3. A Stable Internet Connection

A reliable internet connection is necessary to download the GCC compiler and other essential tools (like MinGW-w64). The installer will retrieve files online, so ensure your connection is active.

4. A Command Line Tool (Command Prompt or PowerShell)

GCC is primarily used via the Command Prompt (cmd) or PowerShell in Windows. You should be comfortable using basic commands like:

bash
cd directory_name
gcc –version

These commands assist in navigating files and verifying if GCC is installed correctly.

5. MinGW or an Alternative GCC Package

Since Windows doesn’t have a built-in GCC compiler, you’ll need to install it manually. The most popular method is through MinGW-w64, which includes:

  • GCC (compiler)
  • G++ (for C++ programs)
  • Other necessary tools

Alternative Options:

  • Cygwin (a Linux-like environment for Windows).
  • WSL (Windows Subsystem for Linux) if you prefer a Linux environment.

6. Setting Up Environment Variables (Optional but Recommended)

To use GCC from any location in the command line, you might need to add it to the system’s PATH. This step ensures that Windows recognizes GCC commands universally.

Note: Once you have these prerequisites, you are ready to install GCC on Windows.


Also Read: How Can You Find The Location of the Windows Log Files?


Features of GCC Compiler

The GCC (GNU Compiler Collection) is a powerful tool that converts human-readable programming code into machine-readable instructions. Developers widely use it for its flexibility, speed, and support for multiple languages. Here are some of its key features:

1. Supports Multiple Programming Languages

GCC can compile programs written in different languages like:

  • C
  • C++
  • Objective-C
  • Fortran
  • Ada
  • Go

That is why the GCC compiler is so versatile for various development needs.

2. Cross-Platform Compatibility

GCC works on different operating systems, including:

  • Windows (via MinGW-w64 or Cygwin)
  • Linux
  • MacOS

This allows you to write code once and compile it on various systems.

3. Open-Source and Free

GCC is entirely free and open-source, which signifies:

  • Anyone can download and use it without paying.
  • Developers can modify and improve it.

This makes it a popular choice in academia, open-source projects, and commercial development.

4. Optimized Code Compilation

GCC improves the performance of programs by optimizing the compiled code.

It can:

  • Reduce memory usage.
  • Improve execution speed.
  • Remove unnecessary parts of the code.

This leads to quicker and more efficient programs.

5. Supports Debugging and Error Detection


GCC offers detailed error messages to assist programmers in identifying and correcting mistakes in their code. It also supports debugging tools such as GDB (GNU Debugger) for troubleshooting programs.


6. Allows Cross-Compilation

GCC can generate code for a system that is different from the one it is running on. For example, you can use GCC on Windows to compile a program that will run on Linux. This is useful for software development across multiple platforms.

7. Supports Different Compilation Options

GCC lets you customize the compilation process using flags and options. For example:

-o → To specify an output file name
-Wall → To show warnings
-O2 → To optimize the code for better performance

These options provide developers greater control over the compilation of their code.


Also Read: How to Fix Remote Desktop Connection Has Stopped Working?


*Important Note:

GCC is a powerful, free, and widely used compiler. It supports various programming languages, optimizes code, and offers excellent debugging tools. Due to these features, it remains a top choice for developers globally.

Steps to Install GCC Using MinGW-w64

The easiest way to install the GCC compiler on Windows is to use MinGW-w64. Below is a step-by-step guide to help you install and set it up.

Step 1: Download MinGW-w64

1. Open your web browser and go to the MinGW-w64 official website:
https://www.mingw-w64.org/

2. Click on the ‘Downloads’ section.

3. Select the latest version of MinGW-w64 for Windows.

4. Choose the correct architecture (64-bit or 32-bit) based on your system.

5. Download the installer (.exe file).

Step 2: Install MinGW-w64

1. Run the downloaded installer (mingw-w64-install.exe).

2. Select the installation directory (e.g., C:\mingw-w64\).

3. Choose the architecture (x86_64 for 64-bit or i686 for 32-bit).

4. Keep all default settings and click ‘Next’ to install.

5. Wait for the installation to complete, then click ‘Finish.’

Step 3: Add MinGW-w64 to System PATH (Important!)

To use GCC from the command line, you must add it to the system PATH.

1. Open the ‘Start Menu’ and search for ‘Environment Variables.’

2. Click on ‘Edit the system environment variables.’

3. In the ‘System Properties’ window, click on ‘Environment Variables.’

4. Under ‘System Variables’, find and select ‘Path’, then click ‘Edit.’

5. Click ‘New’ and add the following path (assuming you installed it in C:\mingw-w64\):

makefile

C:\mingw-w64\bin

6. Click ‘OK’ to save and close all windows.

Step 4: Verify the Installation

1. Open ‘Command Prompt (cmd).’

2. Type the following command and press ‘Enter’:

css

gcc –version

3. If the installation is successful, you should see the ‘GCC version information’ displayed.

Step 5: Compile a Test Program (Optional Step)

To check if GCC is working properly, create a simple ‘C program’:

1. Open ‘Notepad’ and type this code:

c

#include <stdio.h>


int main() {
    printf(“Hello, GCC!\n”);
    return 0;
}

2. Save it as ‘test.c’ (select All Files while saving).

3. Open ‘Command Prompt’ and navigate to the file location using:

pgsql


cd path\to\file

4. Compile the program using:

nginx

gcc test.c -o test.exe

5. Run the compiled program:

test.exe

6. You should see the output:

Hello, GCC!

*Important Note:

Congratulations! You have successfully installed GCC on Windows using MinGW-w64. Now, you can begin compiling and running C/C++ programs directly from your system.


Also Read: How to Install MySQL Server in Windows?


Installing GCC on Windows via Subsystem for Linux (WSL)

If you prefer a Linux-like environment on Windows, the best way to install GCC is through Windows Subsystem for Linux (WSL). This method allows you to run Linux commands directly on Windows and install GCC just like you would on a real Linux system.

Step 1: Enable WSL on Windows

1. Open PowerShell as Administrator

  • Click on ‘Start’, search for ‘PowerShell’, and select ‘Run as Administrator.’

2. Enable WSL by running this command:

powershell

wsl –install

This installs WSL and the default Linux distribution (Ubuntu).

3. Restart your computer once the installation is complete.

Step 2: Open WSL and Set Up Ubuntu

1. After restarting, open Command Prompt (cmd) and type:

nginx

wsl

➔ This will launch Ubuntu (or another installed Linux distribution).

2. Set up your Linux user by creating a username and password when prompted.

Step 3: Update the Package List

Before installing GCC, update your Linux packages by running:

bash

sudo apt update && sudo apt upgrade -y

This ensures you get the latest software versions.

Step 4: Install GCC Compiler

1. Run the following command to install GCC and G++ (for C++):

bash

sudo apt install gcc g++ -y

Wait for the installation to complete.

Step 5: Verify the Installation

1.Check if GCC is installed by running:

bash

gcc –version

You should see the installed GCC version displayed.

Step 6: Compile and Run a Test Program (Optional)

To check if GCC is working, create a simple C program:

1Open Ubuntu (WSL) and create a new file:

bash

nano test.c

➔ Type this sample code:

c

#include <stdio.h>

int main() {
    printf(“Hello, WSL!\n”);
    return 0;
}

2. Save the file (Ctrl + X → Y → Enter).

3. Compile the program:

bash

gcc test.c -o test

4. Run the compiled program:

bash

./test

5. You should see the output:

Hello, WSL!

*Important Note:

You have successfully installed GCC on Windows using WSL. Now, you can enjoy a Linux-like development environment on Windows without a virtual machine.


Also Read: How to Launch Windows Internet Information (IIS) Manager?


Conclusion

Installing the GCC compiler on Windows may seem daunting at first, but with the right approach, it becomes a simple process. Whether you opt for MinGW-w64 for a native Windows installation or WSL (Windows Subsystem for Linux) for a more Linux-like experience, you have the tools to compile and run your C/C++ programs efficiently.

By adhering to the provided step-by-step guides, you’ve successfully:

✓ Installed GCC using MinGW-w64 or WSL

✓ Configured your system for smooth operation

✓ Compiled and executed a test program

With GCC now established, you can immerse yourself in coding, debugging, and project building without limits. Whether you’re a beginner learning programming or an experienced developer working on advanced applications, GCC on Windows offers the flexibility and performance essential for software development.

So, what’s next? Begin writing your first C or C++ program, explore advanced compilation options, or even contribute to open-source projects! The possibilities are endless.

Get Started with GCC Installation on Windows Today!

Worried-about-website
You Need Highly Secured Servers

Get top-notch Windows VPS servers with Robust security