How to Install GCC on Windows

September 23, 2024

Introduction

The GNU Compiler Collection (GCC) is a versatile set of compilers developed by the GNU Project. It supports a wide range of programming languages like C, C++, Fortran, and Go. Originally built for the GNU operating system, GCC has become an essential tool across multiple platforms, including Windows.

While GCC typically comes preinstalled on many Linux distributions, this is not the case with Windows. Additionally, due to differences in system architecture, installing GCC on Windows can be a bit more involved.

In this tutorial, you will learn to install GCC on Windows.

Install GCC on Windows - a tutorial.

Prerequisites

Install GCC on Windows via MinGW-w64

The minGW-w64 tool collection provides a straightforward way to install the GCC compiler and related Windows tools, supporting 32-bit and 64-bit architectures. This section outlines the steps for installing GCC using minGW-w64.

Step 1: Download MinGW-w64

Navigate to the GitHub minGW-w64 page and scroll down to the Assets section. From the list of files, select the one you want to use on your system:

Downloading the mingw-w64 tool collection.

We use Windows 11 64-bit and will download the x86_64-14.2.0-release-posix-seh-ucrt-rt_v12-rev0.7z release. This version uses modern Windows runtime (ucrt), POSIX threading for cross-platform compatibility, and SEH for 64-bit Windows exception handling.

Step 2: Unpack Archive

Extract the downloaded archive to a folder that is easy to access. For example, we will place it at the root of the C drive:

C:\mingw64

After extracting the archive, navigate to the bin folder and copy the folder path. Add the path to the system's PATH environment variable for it to function.

Copying the mingw64 folder path.

Step 3: Set Path Environment Variable

This section shows how to set the PATH environment variable on Windows to instruct the system where the executable files are.

1. Press the Windows key and search for Environment variables. Press Enter to open the System Properties window and click the Environment Variables button.

Opening system properties in Windows.

2. Under the System variables section, find Path, select it, and click Edit...

Editing the Path system variable in Windows.

3. Click New and paste the path to the bin folder from the previous step.

Adding a new entry to the path variable.

4. Click OK in each window to apply the changes.

5. Check if GCC was properly installed by opening the Command Prompt and running the following command:

gcc --version
Verifying GCC installation on Windows.

The system should output the program version, which means that it has been properly installed.

Install GCC on Windows via Chocolatey

Another way to install GCC on Windows is to use Chocolatey, a package manager designed for the Windows OS. It simplifies the process of installing, updating, and managing software through the command line. It is especially useful for developers and system administrators because it reduces the time and effort required to download and configure tools like GCC manually.

The upside is that Chocolatey completely automates the installation, while the downside is that you will probably not get the bleeding edge version you would get from installing manually.

Follow the steps below to install GCC via Chocolatey:

Note: If you don't have Chocolatey installed, check out our guide on how to install Chocolatey on Windows. The guide explains the process step-by-step and offers tips on getting started with the package manager.

Step 1: Install mingw

Open the Command Prompt as an administrator and run the following command to install the mingw installer:

choco install mingw
Install mingw using Chocolatey.

When prompted, type y and press Enter to confirm the installation.

Step 2: Confirm Installation

After the installation process completes, close and reopen the Command Prompt or run the following command to load the changes made to the PATH environment variable:

refreshenv
Refreshing environment variables in the Command Prompt.

Confirm the installation by checking the GCC program version:

gcc --version
Verifying GCC installation using Chocolatey.

Install GCC on Windows via Subsystem for Linux (WSL)

Windows Subsystem for Linux (WSL) allows you to run a Linux environment directly on Windows. Doing so enables you to install and use GCC as you would on a native Linux system.

Follow the steps listed in the sections below.

Step 1: Enable Windows Subsystem for Linux

WSL is a preinstalled feature on new Windows versions. However, you still need to enable it and install a Linux distribution to use it:

1. Press the Windows key and type powershell. Select the Run as administrator option from the right panel to open PowerShell as Administrator.

2. Run the following command to enable WSL and install Ubuntu:

wsl --install
Installing WSL on Windows.

Note: Ubuntu is installed by default when enabling WSL. Run wsl --list --online to see a list of other available distros, and install one using the syntax below:

wsl --install -d [distro_name]

3. Restart the system when prompted and the installation continues automatically. Type in the username and password you want to use for your Linux distro:

Completing WSL installation.

Step 2: Install GCC on WSL

After the installation process completes, you can install GCC:

1. Refresh the package list:

sudo apt update

2. Install GCC with:

sudo apt install build-essential -y

Step 3: Verify GCC Installation

In the Linux terminal, run the following command to confirm the installation:

gcc --version
Verifying GCC installation on WSL.

Conclusion

This tutorial showed how to install GCC on a Windows system using three different methods. GCC supports a wide range of programming languages and provides a robust, open-source platform for compiling code, making it essential for software development.

Next, learn how to install the GCC compiler on Ubuntu, or check out our list of 15 best DevOps tools on the market.

Was this article helpful?
YesNo
Bosko Marijan
Having worked as an educator and content writer, combined with his lifelong passion for all things high-tech, Bosko strives to simplify intricate concepts and make them user-friendly. That has led him to technical writing at PhoenixNAP, where he continues his mission of spreading knowledge.
Next you should read
How to Install and Use Composer on Ubuntu
September 5, 2024

Composer is an application that tracks dependencies for a project, allowing you to specify a set of libraries for a specific project. This guide will help you install and get started with Composer in Ubuntu.
Read more
How to Install Flask on Linux, Windows, and macOS
August 29, 2024

This article explains how to set up a virtual environment for Python in Windows, macOS and Linux. Learn how to install Flask and create a simple web application.
Read more
How to Install Terraform on Windows, Linux, and macOS
August 8, 2024

This guide will show you how to install Terraform on Windows, Linux, and macOS. Choose the section for your OS and follow the instructions.
Read more
How to Install Ansible on Ubuntu
June 5, 2024

Ansible is a management system that helps you manage a large number of servers without special tools. This guide covers the steps for installing Ansible on Ubuntu.
Read more