Some Mac users might want to install GCC on their MacOS computers. GCC, short for Gnu Compiler Collection, is widely used for compiling code in languages like C, C , Objective C, Go, Fortran, Ada, etc., and is often used for writing software or command line tools, whether for academic purposes or practical applications.
By default, Mac systems do not include GCC, but it can be installed relatively easily.
Steps to Install GCC on Mac
We will break this down into three steps: installing Command Line Tools, then installing HomeBrew, and finally installing GCC. This guide assumes you're using a recent version of MacOS (macOS Ventura or MacOS Monterey) and have an active internet connection.
Open Terminal via Spotlight by pressing Command Spacebar and typing "Terminal" followed by hitting return.
At the command prompt, enter the following to start the installation of Command Line Tools:
xcode-select --install
Agree to install the Command Line Tools package. Once completed, you can proceed to install HomeBrew with the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After HomeBrew finishes installing, you can install gcc with this command:
brew install gcc
Upon completion, verify the installation and functionality of gcc by running:
gcc --version
GCC should now be installed on your Mac, ready to compile code or serve your intended purpose.
Why can’t I just use gcc right after installing Command Line Tools on Mac?
While you can attempt to use the gcc command after installing Command Line Tools, it actually invokes clang. Apple places a gcc binary in /usr/bin/gcc that merely runs clang LLVM (try it yourself by typing 'gcc' and observing the clang error).
To use GCC specifically, you need to install it separately.
When I run ‘gcc’, I get an “xcrun: error: invalid active developer path” error message! What do I do?
If you encounter the “xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun” error message, you need to reinstall the command line tools on your Mac. If you’ve already installed them and recently updated MacOS, you might need to reinstall or update the command line tools through Software Update or by reinstallation.
Notably, you might face the same xcrun invalid active developer path error when trying to use git or other command line tools, and the solution remains the same.
What if I want to compile gcc from source on the Mac?
You can also compile GCC from source on your Mac if you prefer, but using Homebrew as a package manager simplifies the process since it manages all dependencies and libraries for you. Additionally, there are numerous benefits to using Homebrew.
That said, if you wish to compile GCC from scratch, you can download the latest version from the GCC GNU ftp mirror:
https://ftpmirror.gnu.org/gcc/
–
Were you successful in installing GCC on your Mac? Did you face any issues? What are your thoughts on using Homebrew to install GCC on the Mac? Feel free to share your experiences in the comments.
The above is the detailed content of How to Install GCC on Mac. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

If you're using a Mac with multiple monitors, you might be curious about how to display the Dock on all screens or whether it's possible to add a Dock to secondary displays.The good news is that you can configure the Dock to appear on any screen conn

Fortnite is once again available for iPhone and iPad users, bringing joy to many gamers. However, there's still no official version for Mac (at least not yet). Despite that, Apple Silicon Mac owners aren’t completely out of luck—you can run the iOS/i

If you've owned multiple Apple devices over the years, you might find yourself in a situation where some of those older Macs, iPhones, iPads, or other Apple hardware have been sold, given away, or traded. No matter how they left your possession, it's

iCloud Private Relay is an excellent privacy feature included with the iCloud subscription, designed to safeguard your online activity and browsing by masking your IP address (using a temporary one) and encrypting DNS lookups. This prevents third pa

Are you using Screen Time to manage your or your child’s Mac usage? If yes, you likely already know that it allows you to set app limits, schedule downtime on the Mac, and more. Additionally, you can also choose specific apps that remain accessible a

macOS Sequoia is a solid operating system that brings some impressive features like iPhone Mirroring, and while performance is excellent for many users, not everyone experiences the same level of speed. If you're finding macOS Sequoia slower than pre

If you frequently use iMessage, then you've likely shared numerous web links in your chats — maybe an article, a video, a tweet, a song, or anything else. Locating these links later can be quite frustrating, but thankfully there's a simpler method th

Advanced Mac users familiar with the command line can swiftly set up a MacOS Tahoe 26 beta virtual machine by entering a few commands into Terminal, using tart. Tart is a command-line utility for managing virtual machines and offers one of the quicke
