👨‍💻

Installing GCC on macOS Instead of Clang

May 11, 2025

How to Install GCC Instead of Using Clang on macOS

Introduction

  • By default, macOS uses Clang for compiling.
  • This guide demonstrates how to install and use GCC instead of Clang.

Steps to Install GCC

1. Install Homebrew

  • Homebrew is a package manager for macOS.
  • Visit brew.sh website.
  • Copy and paste the installation command into the terminal.
  • Run the command successfully.
  • Add to your .zprofile or .zshrc file.

2. Verify Homebrew Installation

  • Run brew command.
  • Successful output indicates Homebrew is installed.

3. Install GCC via Homebrew

  • Go to the brew.sh website.
  • Search for GCC.
  • Copy the provided command to install GCC.
  • Run this command in the terminal.
  • After installation, quit and reopen the terminal.

Verify Installation

  • Run gcc --version.
  • Initially, it might still show Clang.
  • Run gcc-11 --version to see the newly installed GCC version.

Set GCC as Default

  • Use commands to set GCC as the default compiler.
  • Run where gcc or where g++:
    • First result should be Homebrew's GCC.
    • Second result should be system's Clang.
  • Run gcc or g++ to ensure it prioritizes the Homebrew installation.

Final Steps

  • Quit and reopen the terminal again.
  • Run gcc --version and g++ --version to confirm they point to the Homebrew installation.

Conclusion

  • Following these steps will switch your default compiler from Clang to GCC using Homebrew.
  • Ensure terminal is restarted for changes to take effect.

Thank you for watching!