This guide will help you install everything you need to write and run C/C++ programs on your Mac. We’ll use Apple’s built-in tools, so it’s completely free!
What We’re Installing and Why
Xcode Command Line Tools = Apple’s free C/C++ compiler and development tools. Think of it as the tool that turns your C/C++ code into programs that can actually run on your Mac.
Prerequisites (What You Need First)
macOS 10.9 (Mavericks) or newer
At least 2 GB of free space on your hard drive
Internet connection
Administrator access (your user account password)
Step 1: Open Terminal
Terminal is like Command Prompt on Windows - it lets you type commands to your computer.
Find Terminal:
Press Cmd + Space to open Spotlight search
Type “Terminal” and press Enter
OR go to Applications → Utilities → Terminal
What you’ll see:
A window with white or black background
Text that ends with a $ symbol - this is where you’ll type commands
Step 2: Install Xcode Command Line Tools
This is the main step that installs your C/C++ compiler.
Type this command exactly:
xcode-select --install
Press Enter and follow the prompts:
A popup window will appear asking “Install developer tools?”
Click “Install” (NOT “Get Xcode” - that’s a much larger download)
Click “Agree” to accept the license
Wait for the download and installation (this can take 10-30 minutes depending on your internet)
When it’s done:
You’ll see “The software was installed successfully”
Click “Done”
Step 3: Test Your Installation
Let’s make sure everything is working properly!
Test the C compiler:
In Terminal, type: gcc --version
Press Enter
You should see something like:
Apple clang version 13.1.6 (clang-1316.0.20.6)
Target: x86_64-apple-darwin21.3.0
Thread model: posix
Test the C++ compiler:
Type: g++ --version
Press Enter
You should see similar version information
If both commands show version information, congratulations! Your setup is complete!
What if Something Goes Wrong?
Problem: “command not found” when typing gcc
This means the installation didn’t complete properly. Here’s how to fix it:
Check if tools are installed:
xcode-select -p
If this shows a path like /Applications/Xcode.app/Contents/Developer or /Library/Developer/CommandLineTools, you’re good
If it shows an error, the tools aren’t installed properly
Try installing again:
xcode-select --install
If it says “already installed” but gcc still doesn’t work:
Try installing the full Xcode from the App Store
Open App Store → Search for “Xcode” → Install Xcode
After installation, open Xcode once to complete setup
Write your first program - Try creating more C/C++ programs
Practice - Get comfortable with compiling programs using gcc and g++
Understanding What You Installed
gcc = The C compiler (actually Apple’s version called clang)
g++ = The C++ compiler (also Apple’s clang)
clang = Apple’s modern C/C++ compiler that powers both gcc and g++
Xcode Command Line Tools = The package that includes all these compilers
Important Note: On Mac, when you type gcc or g++, you’re actually using Apple’s clang compiler. It works exactly the same way as traditional gcc, so don’t worry about the difference!
Your Mac is now ready for C/C++ programming!
Troubleshooting Tips:
Keep Terminal open while programming - you’ll use it to compile programs
If something doesn’t work, try restarting Terminal
The installation is large, so make sure you have a stable internet connection