Install C++ on Macintosh

Glenmore Marshall offers the following instructions for installing C++ on your Macintosh.

See if your Mac already has C++

Check first if you have C++ in Terminal.app. gcc is c++ through Homebrew and it works as in class using the g++ command in Terminal.app.

gcc --version

clang is the version of C++ used by Mac with Xcode. It is usually installed on newer Mac computers and can be updated using brew or installing Xcode using the Mac app store. Use the clang command in Terminal.app as you would c++/g++ in class

clang --version

Install Homebrew on your Mac

If you do not already have c++ installed, install Homebrew using the command below in Terminal.app.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

You can also use this link and use the .pkg installer if you are familiar with GitHub:
https://github.com/Homebrew/brew/releases/tag/4.4.20

Install C++ on your Mac

To use brew to install c++, choose one of the following. You do not need to install both.

  1. To install c++,
    brew install gcc
    
  2. To install clang,
    brew install llvm
    

Package management

To see what version of a package you are using, and if it is installed:
"package name" --version
For example,

gcc --version
or
g++ --version
clang --version

To update a specific package:
brew upgrade "package name"
For example, to update C++,

brew upgrade gcc