Course contentsShow
C
Lesson 10 of 1,2191. FoundationsFree lesson

Installing GCC on Linux/macOS

Installing GCC on Linux/macOS

What you'll learn: How to install and verify the C compiler that transforms your human-readable code into a format your computer's processor can execute.

The Translator in Your Computer

Think of your computer like a giant industrial factory that only speaks a very specific dialect of "Electricity." As a human, you write C code, which looks like a mix of math and English. To get the factory to build your program, you need a professional translator. In the world of C, that translator is called a compiler.

GCC (the GNU Compiler Collection) is the most famous and widely used compiler in history. Before you can write a single line of C, you need to make sure this translator is sitting in your system's "office," ready to work.

Getting the Tools

If you are on Linux, you likely already have a package manager—think of it like an app store for your command line. To install GCC, open your terminal and type:

  • Ubuntu/Debian: sudo apt update && sudo apt install build-essential
  • Fedora: sudo dnf install gcc gcc-c++

If you are on macOS, Apple provides these tools through a package called "Command Line Tools." Open your terminal and type: xcode-select --install A popup will appear asking if you'd like to install the tools. Click "Install" and wait for it to finish.

Verifying the Installation

Once the installation is complete, you need to check if the translator is actually standing by. We do this by asking the compiler to identify itself. Type this into your terminal:

gcc --version

If you see a wall of text that includes a version number (like gcc 11.4.0 or Apple clang version...), you are successful! Even if macOS shows "Clang," don't worry—it acts as a drop-in replacement for GCC for our purposes.

If your terminal says "command not found," the installation failed or your computer doesn't know where the tool is hiding.

Your First "Check"

To ensure it works, we don't even need a file yet. Running this command tells the compiler to check a blank input:

// This is what the compiler looks for: a main entry point
int main() {
    return 0;
}

By typing gcc -v, you have confirmed that your toolchain is linked and ready to turn your future text files into powerful software.

Key takeaway

Installing GCC provides the essential "translator" needed to convert C source code into runnable programs.