What GCC is and why you might need it
GCC (GNU Compiler Collection) is a set of programming tools that turns code you write into programs your computer can run. If you're learning to program in C, C++, or several other languages, or if you're installing software from source code rather than a pre-built installer, you'll need GCC on your machine.
GCC is free and open-source. It runs on Windows, macOS, and Linux. The installation process differs depending on which operating system you use, but the end result is the same: a compiler that can build code on your own computer.
Key Takeaways
- On macOS, install GCC through Xcode Command Line Tools by running xcode-select --install in Terminal.
- On Windows, download MinGW or use Windows Subsystem for Linux (WSL) to get a full Linux environment with GCC built in.
- On Linux, use your distribution's package manager: apt install gcc on Ubuntu/Debian, dnf install gcc on Fedora, or pacman -S gcc on Arch.
- After installation, verify GCC works by opening a terminal and typing gcc --version.
- You'll also want a text editor or IDE to write code in; popular free options include Visual Studio Code and Code::Blocks.
Installing GCC on macOS
On macOS, GCC comes as part of Xcode Command Line Tools, Apple's set of development utilities. You don't need to install the full Xcode application—just the command-line tools, which are much smaller.
Open Terminal (find it in Applications > Utilities, or press Command + Space and type "Terminal"). Type this command and press Enter:
xcode-select --install
A dialog box will appear asking you to install the tools. Click Install, agree to the license, and wait for the download and installation to finish. This usually takes 5 to 15 minutes depending on your internet speed. When it's done, close the dialog.
To confirm the installation worked, type gcc --version in Terminal. You should see version information printed back to you.
Installing GCC on Windows
Windows doesn't come with GCC, so you have two main routes: MinGW (Minimalist GNU for Windows) or Windows Subsystem for Linux (WSL).
MinGW is simpler if you just want GCC. Go to the MinGW-w64 project website, download the installer for your system (64-bit or 32-bit), and run it. During installation, choose the default settings. The installer will ask where to put the files—the default location is fine. After installation finishes, you need to add MinGW to your system PATH so Windows knows where to find GCC.
Right-click This PC or My Computer, select Properties, then click Advanced System Settings. Click Environment Variables. Under System Variables, find the one called PATH, click it, then click Edit. Click New and type the path where you installed MinGW (usually C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin, but check your actual installation folder). Click OK three times to close all the dialogs.
WSL is better if you plan to do serious development work. Open PowerShell as Administrator (right-click PowerShell and select Run as Administrator) and type:
wsl --install
This downloads and installs a Linux environment inside Windows. Restart your computer when prompted. After restart, open PowerShell again and type wsl to enter the Linux environment. You're now in a Linux terminal, and GCC is already installed. Type gcc --version to confirm.
Installing GCC on Linux
Most Linux distributions come with GCC already installed, but if yours doesn't, installation is a single command in your package manager.
On Ubuntu or Debian-based systems, open a terminal and type:
sudo apt update
Then:
sudo apt install gcc
On Fedora or Red Hat-based systems, type:
sudo dnf install gcc
On Arch Linux, type:
sudo pacman -S gcc
Your system will download and install GCC automatically. When it finishes, type gcc --version to verify it's working.
Verifying your installation
After installation on any operating system, open a terminal (or PowerShell on Windows) and type:
gcc --version
If GCC is installed correctly, you'll see output like "gcc (GCC) 11.2.0" or similar, showing the version number. If you see "command not found" or "gcc is not recognized", the installation didn't complete or GCC isn't in your system PATH. On Windows, go back and check that you added MinGW to your PATH correctly. On macOS or Linux, try reinstalling.
You can also test that GCC actually compiles code. Create a file called hello.c with this content:
#include <stdio.h>int main() { printf("Hello, World!\n"); return 0;}
Save it, then in the same folder, type:
gcc hello.c -o hello
This tells GCC to compile hello.c and create a program called hello. If there are no error messages, the compilation worked. Run the program by typing ./hello on macOS or Linux, or hello.exe on Windows. You should see "Hello, World!" printed to the screen.
Choosing an editor or IDE to write code in
GCC is just the compiler—it turns code into programs. You still need a text editor or IDE (integrated development environment) to write the code itself. You can use any text editor, but some are designed specifically for programming.
Visual Studio Code is free, lightweight, and works on all three operating systems. Download it from code.visualstudio.com, install it, then add the C/C++ extension from the Extensions marketplace inside the app. It will automatically find your GCC installation.
Code::Blocks is a free IDE designed specifically for C and C++. It includes GCC on Windows (so you don't need to install MinGW separately) and works on macOS and Linux too. Download it from codeblocks.org.
Geany is a lightweight editor that works on all platforms and has built-in support for compiling C code with GCC. It's simpler than Code::Blocks if you're just starting out.
None of these are required—you can write code in Notepad and compile from the terminal—but they make the process faster and catch some mistakes before you compile.
Frequently Asked Questions
Do I need to install anything else besides GCC?
GCC alone is enough to compile code, but you'll want a text editor to write in. You may also want make, a tool that automates compilation of large projects. On macOS and Linux, make usually comes with GCC. On Windows with MinGW, you can install it separately; with WSL, it's already there.
What's the difference between GCC and Clang?
Clang is another C/C++ compiler that works similarly to GCC. Both are free and open-source. GCC is more widely used and comes pre-installed on most Linux systems. Clang is the default on macOS. For learning, either works fine; the choice matters more for large projects where performance or specific features matter.
Can I use GCC on a Chromebook?
Not directly on Chrome OS itself, but you can enable Linux on your Chromebook (available on most newer models). Once Linux is running, GCC installs normally using your Linux distribution's package manager, just like on any other Linux computer.
Why does my code compile but won't run?
Compilation and running are two different steps. GCC turns your code into a program, but the program might have logic errors or runtime problems that only show up when you run it. Check that you're running the compiled program (not the source code file), and read any error messages it prints carefully.
Is GCC free to use commercially?
Yes. GCC is licensed under the GNU General Public License (GPL), which means you can use it for any purpose, including commercial software. The GPL requires that if you distribute software compiled with GCC, you make your source code available under the same license—but using GCC itself is completely free with no restrictions.