How to Install GCC on Mac: a step-by-step guide

The Mac does not come with GCC by default, but you can install GCC onto a Mac with a few simple steps

By Chris Smith - Senior Editor
2 Min Read

If you are a Mac user, you may want to install GCC onto your MacOS computer. GCC, or the GNU Compiler Collection, has been around since the 1980s, predating Linux itself. Not only does it compile C programs, but also handles C , Objective-C, Objective-C , Fortran, ADA, Go, and more languages, and is frequently used for compiling command line programs, writing software, and more, whether for computer science classes or for using command line tools.

The Mac does not come with GCC by default, but you can install GCC onto a Mac with a few simple steps.

How to Install GCC on Mac

The method we’re going to use in this guide involves three steps; installing Command Line Tools on the Mac, then installing HomeBrew, and finally installing GCC. We’re going to assume you’re running a modern version of MacOS and have an internet connection.

Let’s get started:

  1. Launch the Terminal application with Spotlight by pressing Command Spacebar and typing "Terminal" and pressing return
  2. At the command line, enter the following to begin installing Command Line Tools:
    xcode-select --install
  3. Agree to install the Command Line Tools package, when that is complete you can now install Homebrew package manager onto the Mac with the following command string:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  4. After Homebrew has finished installing, you can install gcc with the following command:
    brew install gcc
  5. When finished, you can confirm that gcc has installed and is working by running the following command:
    gcc --version

GCC will now be installed on the Mac, and you can run it as usual to compile code, or whatever else your intended usage of gcc is.

Why can’t I just run gcc after installing Command Line Tools on Mac?

You can try using the gcc command after installing Command Line Tools, however, it’s actually clang.

Apple places a gcc binary in /usr/bin/gcc but it just runs clang LLVM (try it yourself, just type ‘gcc’ and you’ll see a clang error).

You need to manually install GCC separately to run GCC on the Mac.

When I run ‘gcc’ I get an "xcrun: error: invalid active developer path" error message! Help!

If you see the "xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun" error message, you need to install command line tools on the Mac. If you have already installed command line tools, and have recently updated MacOS, you may need to install them again, or update command line tools through software update, or again, by reinstalling command line tools.

What if I want to compile gcc from source on the Mac?

You can also compile gcc from source on the Mac if you’re so inclined, but using Homebrew as a package manager will make the job easier for you since it handles all other dependencies and libraries as well.

Nonetheless, if you wish to compile gcc from scratch, you can find the latest version from the GCC GNU ftp mirror:

https://ftpmirror.gnu.org/gcc/

Were you able to successfully install gcc on your Mac? Did you run into any hiccups? What do you think about the ease of using Homebrew for installing gcc on the Mac? Share your thoughts and experiences in the comments.

TAGGED:
Senior Editor
Follow:
Chris Smith is a senior editor at GeeksChalk based in Canada. He likes to think of himself as a jack of all trades (and a master of at least a few), though he mainly focuses on iPhones and Macs. Often covering both at the same time. When not surrounded by various Apple devices while putting them through their paces, Chris can be found streaming the latest movies or series, gaming on his PS5, or getting fresh air on a hike in the beautiful wilderness of British Columbia.
Leave a Comment