How to use/install gcc on Mac OS X 10.8 / Xcode 4.4

XcodeMacosGcc

Xcode Problem Overview


I have install Mountain Lion (Mac OS X 10.8) and now gcc doesn't seem to be available anymore. I've also installed Xcode 4.4 so there is no more /Developer directory.

I need gcc both for mac ports and for ruby gems (that have native extensions).

Does Xcode 4.4 include gcc or is there a way to install gcc?

Xcode Solutions


Solution 1 - Xcode

Update:

You can now just run the following command from your terminal:

xcode-select --install

Starting with Xcode 4.3 - you must now manually install command line tools from Xcode menu > Preferences > Downloads.

manual install image

Alternatively, there are stand-alone installation packages both for Mountain Lion (10.8) and for Mavericks (10.9).

> This package enables UNIX-style development via Terminal by installing > command line developer tools, as well as Mac OS X SDK frameworks and > headers. Many useful tools are included, such as the Apple LLVM > compiler, linker, and Make. If you use Xcode, these tools are also > embedded within the Xcode IDE, and can be installed on your system > using the Downloads preferences pane within Xcode 4.3 and later. This > package requires Mac OS X 10.7.3 or later.

Solution 2 - Xcode

I found that after upgrading from Lion my install was failing because it was looking for GCC in /usr/bin/gcc-4.2. Now the default installation path is /usr/bin/gcc.

My error looked like this:

make: /usr/bin/gcc-4.2: No such file or directory

A symlink will sort out the issue:

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

Solution 3 - Xcode

Just paste this into terminal:

export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH

I hope that helps!

Solution 4 - Xcode

pre-1.9.3 Ruby on Mountain Lion

Pre-requisites

Xcode 4.4, 
Xcode Command Line Tools
Homebrew
XQuartz 2.7.2 or later.
rbenv/ruby-build or RVM.

Install GCC

Note, the Xcode Command Line Tools do not include GCC, they include LLVM-GCC. Same-same, but different.

$ brew tap homebrew/dupes
$ brew install apple-gcc42

Add the following to your ~/.profile or equivalent:

export CC=/usr/local/bin/gcc-4.2

And reload your shell before attempting the install commands below.

Install RVM

CFLAGS="-I/opt/X11/include" rvm reinstall ree

Install Ruby

Prefix the install command with CFLAGS="-I/opt/X11/include"

Then to set your new ruby as default:

user$ rvm use 1.9.2 --default

Then check your ruby version:

user$ ruby -v

Solution 5 - Xcode

For users who can download from Apple a build of Xcode, but not the command line tools

An accepted answer to a comparable question suggests kennethreitz / osx-gcc-installer. In that 'OSX GCC Installer' area, the first of two options is pre-built binaries — for Snow Leopard and for Lion, but not for Mountain Lion. Considering what's included, I should not recommend using that project's GCC-10.7-v2.pkg after installing version 4.4 of Xcode on any build of 10.8.

The more relevant option is build your own, with reference to Apple open source for Developer Tools.

Sources for GCC, compatibility with 10.8

Apple Open Source for the most recently published Developer Tools 4.3 is without GCC. The source for GCC in the 4.1 area may be too old for use with 10.8.

GCC home page for the most recent release.

Build status for GCC 4.7 links to results for x86_64-apple-darwin10.8.0 …

Solution 6 - Xcode

Apple provides an .mpkg installer for the Command Line Tools (CLT), but they don't normally expose the link. It includes GCC. You can install it without downloading/installing XCode.

Download Command Line Tools w/ GCC here.

Solution 7 - Xcode

You can compile it yourself with this Makefile. If you want to save yourself 2-5 hours, I created a signed installer package with GCC 4.7.2 for Mac OSX Mountain Lion which you can download here.

Solution 8 - Xcode

You can download the installer(.pkg file) lattest version of GCC for Mountain Lion from this site. You simpy need to download and install it.

https://github.com/kennethreitz/osx-gcc-installer/downloads

Solution 9 - Xcode

I'm using OS X 10.9 Mavericks. I only happened to type gcc -v. The system downloaded gcc immediately. Installation completed without Xcode being installed at all. Testing "Hello, world!" works.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAthir NuaimiView Question on Stackoverflow
Solution 1 - XcodeSteveView Answer on Stackoverflow
Solution 2 - XcodeVolcanicView Answer on Stackoverflow
Solution 3 - XcodeRoger Fernandez GuriView Answer on Stackoverflow
Solution 4 - XcodeSerge PedrozaView Answer on Stackoverflow
Solution 5 - XcodeGraham PerrinView Answer on Stackoverflow
Solution 6 - XcodebriangonzalezView Answer on Stackoverflow
Solution 7 - XcodebbaassssiieeView Answer on Stackoverflow
Solution 8 - XcodenbsView Answer on Stackoverflow
Solution 9 - XcodePongthepView Answer on Stackoverflow