After installing Xcode 4.3.1 on OS X Lion, I have lost my GCC compiler. I need this for my study. Does anyone know how I will install this? All I have been able to find was people suggesting to install Xcode 4.3.1 but with the latest Xcode build, Apple has moved the GCC compiler inside the Xcode.app and it doesn't seem to be the same version of the GCC compiler as the one bundled with previous versions of Xcode.

3 Answers 3


Open XCode go to preferences under downloads install command line tools

  • 2
    This was definitely the easiest way to do it. Thanks.
    – SimonBS
    Apr 20, 2012 at 7:13

There have been a couple of blog posts about how to do this recently, in the context of trying to compile Ruby 1.8.7 (mine and others). The short answer:

Install Command Line Tools (in Xcode: Preferences > Downloads > Components; or you can go to Apple and download them separately if you don't have/want Xcode installed) - this installs a gcc command, but it's actually clang Install Homebrew (instructions), a package manager for OS X

Then, install the 'dupes' homebrew repository and from it the genuine GCC 4.2 compiler:

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

/usr/bin/gcc will still be i686-apple-darwin11-llvm-gcc-4.2, but /usr/local/bin/gcc-4.2 will be i686-apple-darwin11-gcc-4.2.1 (and associated tools, g++-4.2 and so forth, also in /usr/local/bin)

Then, you can use whatever mechanism your build process uses (for instance, setting the CC and CXX environment variables appropriately) to select those compilers rather than the clang versions.

  • I really wish I had found your solution a few days ago. I fought it for two days straight. I'd +20 if I could.
    – Chance
    Mar 24, 2012 at 15:13

I don't use Xcode 4.3 for actual Xcode Projects, only for command line source compilation, and had the same issue. You can bring back your gcc and cc commands with the below commands from terminal:

cd /usr/bin
rm cc gcc c++ g++
ln -s gcc-4.2 cc
ln -s gcc-4.2 gcc
ln -s c++-4.2 c++
ln -s g++-4.2 g++

This will make system wide changes, so be sure that's what you want before doing it.

For these commands to work you'll also need the Command Line Tools for Xcode to be installed, if you don't already have them installed. The Tools can be installed through Xcode's downloads preference pane.

  • 2
    One suggestion: instead of removing the old binaries (line 2 of the script), perhaps just put them in an archive directory under /usr/bin). That way if you need them you can still invoke them by absolute path. Mar 13, 2012 at 13:10
  • Good suggestion. Do with them as you will, even: mv cc cc.orig && mv gcc gcc.orig or some such thing.
    – Lantrix
    Mar 14, 2012 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.