How to Install GCC on Mac

May 2, 2023 - 3 Comments

Installing GCC on a Mac

Some Mac users may wish to install GCC onto their MacOS computers. GCC, which stands for Gnu Compiler Collection, is a commonly used compiler with support for C, C++, Objective C, Go, Fortran, Ada, 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 relative ease.

How to Install GCC on Mac

The approach we’re going to use here 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 (this tutorial is written with macOS Ventura or MacOS Monterey) and have an internet connection.

  1. Open the Terminal application with Spotlight by hitting Command+Spacebar and typing “Terminal” and hitting return
  2. At the command line, enter the following to begin installing Command Line Tools:
  3. xcode-select --install

  4. 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:
  5. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  6. After Homebrew has finished installing, you can install gcc with the following command:
  7. brew install gcc

  8. When finished, you can confirm that gcc has installed and is working by running the following command:/li>
    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.

For what it’s worth, you may see the same xcrun invalid active developer path error when trying to use git and many other command line tools, and the solution is the same.

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, and there are many other tips and advantages with using Homebrew.

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.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

3 Comments

» Comments RSS Feed

  1. Steve Baumgartner says:

    When Homebrew installs gcc, it appends a version number to the name. So, for example, to run gcc version 13.1.0 (the latest) you must type “gcc-13”. Bare “gcc” will still get clang.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site