Lesson 3 of 6
If you're on Windows or Linux, skip to the lesson for your system — this one's macOS-only.
The one command you need
macOS ships with a compiler, but it's not installed by default — it comes bundled inside Apple's developer tools. You don't need to install the full Xcode app (which is a multi-gigabyte download); the command line tools are a much smaller, separate install.
Open Terminal (search for it with Spotlight — Cmd+Space, then type "Terminal") and run:
xcode-select --install
A window will pop up asking to install the command line developer tools. Click Install, agree to the license, and wait — this can take a few minutes depending on your internet connection.
Confirm it worked
Once the install finishes, check that the compiler is there:
g++ --version
On macOS this actually runs Apple's Clang compiler (which understands the g++ command as an
alias) — that's expected and fine. You should see version information printed. If you instead see
a prompt to install the command line tools again, the install from above didn't finish — repeat
it.
Working with your files
Create a folder for this course:
mkdir ~/cpp-course
cd ~/cpp-course
~ means your home folder, so ~/cpp-course is a new folder right inside it. You'll come back
here every lesson.
Checkpoint
- macOS's compiler comes from Apple's command line developer tools, not a separate download.
xcode-select --installinstalls them — click through the popup that appears.g++ --versionconfirms it worked (it'll report itself as Clang, which is correct on macOS).- Next up: installing VS Code and the C++ extension.
Questions about this lesson
Log in to ask a question.