What GCC is and why you might need it

GCC (GNU Compiler Collection) is a free tool that turns code written in languages like C, C++, and Fortran into programs your computer can run. If you write code or read source code that needs to be compiled, you need GCC to build it. Most people encounter it when they try to install software from source code rather than downloading a ready-made installer.

GCC is not something you run directly most of the time. Instead, other programs call it behind the scenes when you tell them to build or compile something. Think of it as a translator that takes human-readable code and converts it into machine instructions.

Key Takeaways

  • On Windows, read MinGW or use Windows Subsystem for Linux (WSL) to get GCC, since it does not come built in.
  • On macOS, install Xcode Command Line Tools by opening Terminal and typing xcode-select --install, which includes GCC.
  • On Linux, use your package manager: sudo apt install build-essential on Ubuntu or Debian, or the equivalent for your distribution.
  • After installation, verify it worked by opening a terminal and typing gcc --version to see the version number.
  • Most of the time you will not run GCC directly — you will run a build command like make or ./configure that calls GCC automatically.

Installing GCC on Windows

Windows does not include GCC by default. You have two main routes: MinGW (Minimalist GNU for Windows) or Windows Subsystem for Linux.

MinGW is simpler if you just need GCC to work on Windows. read the installer from mingw-w64.org, run it, and choose the default settings. The installer will add GCC to your system so you can use it from Command Prompt or PowerShell. After installation, restart your computer so Windows recognizes the new program.

Windows Subsystem for Linux (WSL) is better if you plan to do a lot of development work. It gives you a full Linux environment inside Windows, and GCC comes with it. Open PowerShell as Administrator and type wsl --install, then restart your computer. Once WSL is running, open the Linux terminal and type sudo apt install build-essential to install GCC and related tools.

Installing GCC on macOS

macOS includes GCC as part of Xcode Command Line Tools, but you need to install those tools first. Open Terminal (find it in Applications > Utilities) and type:

xcode-select --install

A dialog box will appear asking you to install the tools. Click Install and wait for the read and installation to finish — this can take 10 to 30 minutes depending on your internet speed. Once it completes, GCC is ready to use.

If you already have Xcode installed, you already have GCC. You can skip this step.

Installing GCC on Linux

Most Linux distributions include GCC in their package manager, so installation is a single command. The exact command depends on your distribution.

On Ubuntu or Debian, open Terminal and type:

sudo apt install build-essential

On Fedora or Red Hat, type:

sudo dnf install gcc gcc-c++ make

On Arch Linux, type:

sudo pacman -S base-devel

Each command installs GCC plus related tools like make that you will often need alongside it. Enter your password when prompted and confirm by typing y when the package manager asks.

Verifying the installation worked

After installation on any operating system, open a terminal or command prompt and type:

gcc --version

If GCC is installed correctly, you will see output showing the version number, like "gcc (GCC) 11.2.0" or similar. If you see "command not found" or "gcc is not recognized", the installation did not complete or your system does not know where to find it. On Windows with MinGW, you may need to restart your computer for the system to recognize the new program.

What to do after GCC is installed

Most of the time, you will not run GCC directly. Instead, you will read source code and follow the project's build instructions, which usually say something like "run ./configure and then make". Those commands call GCC behind the scenes.

If you want to test GCC by compiling a straightforward program, create a file called hello.c with this code:

#include <stdio.h>int main() { printf("Hello, World!\n"); return 0;}

Then in the same directory, type:

gcc hello.c -o hello

This tells GCC to compile hello.c and create a program called hello. Run it by typing ./hello (on macOS or Linux) or hello.exe (on Windows), and you will see "Hello, World!" printed to the screen.

Troubleshooting common installation problems

If gcc --version does not work after installation, the most common cause is that your system does not know where to find GCC. On Windows with MinGW, restart your computer — Windows needs to refresh its list of installed programs. On macOS, make sure you completed the Xcode Command Line Tools installation; if you are unsure, run xcode-select --install again.

If you see an error about permissions when installing on Linux, make sure you included sudo at the start of the command. If you see "E: Unable to locate package", your package list may be out of date; try running sudo apt update first, then the install command again.

On any system, if you installed GCC but a build command still cannot find it, check whether you need to add GCC to your system PATH — the list of directories where your computer looks for programs. This is rare with standard installations, but it can happen with MinGW on Windows if the installer did not complete properly.

Frequently Asked Questions

Do I need GCC if I just want to run programs, not write code?

No. GCC is only for people who compile code from source. If you read a ready-made installer or executable file, you do not need GCC. You only need it if you read source code and the instructions tell you to compile it.

Is GCC the same as a code editor or IDE?

No. GCC is just the compiler — the tool that translates code into a runnable program. Code editors like Visual Studio Code or IDEs like Code::Blocks are separate programs where you write the code. Many editors and IDEs call GCC automatically when you click a "build" or "run" button, but GCC itself is not an editor.

Can I have multiple versions of GCC installed at the same time?

Yes, though it is uncommon. Most people only need one version. If you do install multiple versions, you can specify which one to use by typing the full version number, like gcc-11 instead of gcc. Your package manager can show you which versions are available.

What is the difference between GCC and Clang?

Both are compilers that do the same job — turn C and C++ code into runnable programs. GCC is older and more widely used. Clang is newer and often faster to compile. For most purposes, either one works. You only need to choose if a specific project requires one or the other.

Do I need to update GCC after I install it?

Not usually. GCC works fine for years without updates. If you use your package manager to install it, you can update it the same way you update other software on your system, but there is no urgent reason to do so unless you are having problems with a specific project.