C++ Software Setup: Mac Edition
As described in this week's lessons, in CS 70 we use the Clang compiler.
There are other C++ compilers out there, but we'll stick with Clang here to be consistent with what's on the server.
But you're free to look into other options on your own time!
Step 1: Install Clang and Git
On macOS, both the Clang compiler and Git are included in the Xcode Command Line Tools package.
To begin, open the Terminal app (which can usually be found in the Finder under ; you can also hit Command-Space to bring up Spotlight, and search for the string "terminal").
Then, in the terminal window, run
xcode-select --install
This will open a system prompt asking you to confirm the installation. Then it will download and install Xcode Command Line Tools (asking you for your password along the way).
If you already had the full Xcode app installed for a previous class, internship, summer research, or other project, it already comes with Xcode Command Line Tools, so you can skip all the above steps!
Checking Your Clang Installation
To test whether the installation worked, run the following command in the terminal:
clang++ --help | head
You should see the first ten lines of what's actually a massive chunk of documentation for the Clang compiler (over 1800 lines!), which should start with something like the following:
OVERVIEW: clang LLVM compiler
USAGE: clang [options] file...
OPTIONS:
Checking the Git Installation
You can quickly test that Git is working by running
git --help
This should print a ~50-line help summary that starts with something like the following:
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[--config-env=<name>=<envvar>] <command> [<args>]
Step 2: Install Homebrew (Recommended, but Optional)
Homebrew is a package manager for macOS that makes it easy to install and manage software, particularly open-source command-line tools. It's the easiest way to install GitHub CLI, which is a command-line interface for GitHub, and the Helix editor, which is the text editor we use on the CS 70 server.
You can see if you already have Homebrew installed by running
brew --versionin the terminal. If you see a version number, you already have it installed and can skip the next step. If you see an error message, you need to install it.
What about MacPorts?
You can use MacPorts if you prefer, but we're only going to cover Homebrew here.
Installing Homebrew
Go to the Homebrew website and follow the instructions to install Homebrew. The installation process will involve running a (scary-looking) command in the terminal, which will download and install Homebrew on your computer.
Whoa! That command looks like it could do anything! How do I know it's safe?
The truth is, any time you download and install any software from the Internet, you are trusting that the software is safe and won't try to do bad things. This command looks a bit scarier than most, but the project is broadly trusted and widely used.
You can look at the script before you run it by typing
curl -Oin your terminal window and pasting the URL from their command in before hitting Return. That will download theinstall.shfile instead of running it. (The-Oflag tellscurlto use the same name when it saves the file; without it,curljust prints what it downloads to the screen.)
But if you'd like a different option, they do provide alternative installation methods that you can use instead.
Installing GitHub CLI and Helix
Once Homebrew is installed, you can use it to install GitHub CLI and Helix by running the following commands in the terminal:
brew install gh
brew install helix
Is it okay if I don't install Homebrew?
Absolutely. Homebrew isn't the only package manager for macOS, and it's possible to install both GitHub CLI and Helix without it. But Homebrew is the most popular package manager for macOS, and it makes it easier to install and manage software that hasn't been packaged specially for the Mac, so we recommend using it.
Or MacPorts!
Meh. Do I even need these tools at all?
There are other ways to authenticate with GitHub. If you search for
ssh authentication with GitHub, you'll find instructions for setting up SSH keys, which is another way to authenticate with GitHub. But GitHub CLI is the easiest way to do it.
And you're free to use any text editor you like, as long as it does not have AI code completion enabled.
I want MORE editors!! So of course I want Helix on my computer, too!
(When logged in, completion status appears here.)