297

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?

Athir Nuaimi
  • 3,214
  • 2
  • 14
  • 17
  • 2
    Similar, more recently: [Lion — GCC not found, but Xcode is installed — Ask Different](http://apple.stackexchange.com/q/48099/8546) – Graham Perrin Apr 21 '12 at 10:14
  • 32
    The answers on this thread all fail to make one very important point: they are not installing GCC, but rather **Clang/LLVM pretending to be GCC**. This is not a trivial difference, for reasons that I'd hope I don't have to explain. – underscore_d Apr 01 '16 at 19:10

9 Answers9

423

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.

Steve
  • 31,144
  • 19
  • 99
  • 122
  • 5
    When Steve says `Preferences`, he's talking about the Preferences dialog box which can be found in the Xcode menu at the upper left when you have the XCode window active. – David Grayson Apr 17 '12 at 21:10
  • The separate installation package does not currently support mountain lion :/ (July 26) – mjallday Jul 26 '12 at 16:14
  • 2
    @marshall - if you update to Xcode 4.4 which was also released yesterday, you should be good to go - no? Seemed to work for me just fine. – Steve Jul 26 '12 at 18:26
  • @Steve - yep, i was just hoping to avoid waiting on the xcode download before i got started. after installing xcode i was good to go. – mjallday Jul 27 '12 at 17:54
  • @marshall - Yeah. I hear ya. Weren't they (Apple) just making a big deal about how great the new super-small diff-based updates are at the WWDC? 1.5GB update size is hardly "great" IMO. – Steve Jul 27 '12 at 20:13
  • 2
    @marshall: Here's a link to the 10.8 package: https://developer.apple.com/downloads/index.action?=Command%20Line%20Tools%20%28OS%20X%20Mountain%20Lion%29. I just submitted an edit to the answer that uses the correct link. – chrisk Jul 30 '12 at 05:15
  • THANKS! it had been so long since i installed xcode on my machine i forgot about the command line tools. :) – rkstar Jan 30 '13 at 12:43
  • it is crazy how Apple did that. I upgraded from Lion and I had the command line tools installed before. after the upgrade, apparently they were gone! – mavili Apr 26 '13 at 11:51
  • Hi this solved the issue i had with Ruby on Rails installation (MAC OSX - Mountain Lion) Installing json (1.8.0) Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/name/Documents/rails_one_click/ruby/bin/ruby extconf.rb creating Makefile make sh: make: command not found – d1jhoni1b Jul 22 '13 at 20:23
  • @chrisk it's now a broken link :( – gerl Nov 06 '13 at 21:50
  • @gerl is there an error or something? The link still works for me. It did ask me to sign in first, for what it's worth. p.s. here's the new Mavericks version of the package: https://developer.apple.com/downloads/index.action?=Command%20Line%20Tools%20%28OS%20X%20Mavericks%29 – chrisk Nov 17 '13 at 21:05
  • 4
    Doesn't this actually install llvm-gcc instead of gcc? – Tyler Pfaff Apr 02 '14 at 22:44
  • 2
    When i ask for gcc version, I get this as a return: $ /usr/bin/gcc -v Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.0.0 Thread model: posix So am I using gcc? – Thomas Dec 14 '14 at 16:11
  • 2
    This installs `clang`-pretending-to-be-GCC, **not** GCC. – underscore_d Apr 01 '16 at 19:06
43

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
Volcanic
  • 1,572
  • 1
  • 13
  • 5
  • 2
    my gcc-4.2 was actually just in /usr/local/bin, this worked for me: `sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2` – courtsimas Aug 02 '12 at 02:41
  • 2
    Thanks, this was the key to a 10.7 -> 10.8 migration assistant breakage of my commandline tools. – slycrel Dec 31 '12 at 18:56
26

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!

sra
  • 23,820
  • 7
  • 55
  • 89
Roger Fernandez Guri
  • 970
  • 2
  • 10
  • 18
  • 2
    If you don't want to run this every time you load a new terminal window, add this line to your ~/.bashrc or ~/.zshrc – Jered Odegard Jul 26 '12 at 01:03
  • or just add it to your /etc/paths file http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/#.UtU4uGRDs29 – Phill Pafford Jan 14 '14 at 13:16
21

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
idonnie
  • 1,703
  • 12
  • 11
Serge Pedroza
  • 2,160
  • 3
  • 28
  • 41
  • I've found your post very useful, as like as this one, concerning OpenSSL dependency when installing Ruby 2.0.0 via RVM: http://apple.stackexchange.com/questions/83885/ruby-2-0-0-install-via-rvm-errors-surrounding-openssl – idonnie Mar 14 '13 at 15:58
  • Seriously, one among the most helpful answers I've come across lately. Worked perfectly. Exactly what I was looking for. Wish I could upvote more. Thanks! – Bharadwaj Srigiriraju Jun 25 '13 at 19:08
  • This is only answer with the brew recipe for the real gcc, which is what the question title seems to ask for. Thanks! – Gabe Kopley Jul 08 '13 at 21:52
13

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 …

Community
  • 1
  • 1
Graham Perrin
  • 524
  • 1
  • 10
  • 45
6

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.

briangonzalez
  • 1,606
  • 16
  • 21
  • Interestingly, I installed this, but see no resulting gcc version changes in /usr/bin. Just the LLVM versions. Wonder if they install to a separate location now? – JohnMetta Aug 01 '12 at 15:32
  • Looks like you have to add @roger's link to the XCode directory to your path. – JohnMetta Aug 01 '12 at 15:55
  • @JohnMetta does it make an Xcode directory even if you haven't installed Xcode? – briangonzalez Aug 01 '12 at 16:25
  • You know, I'm uncertain about that b/c I had XCode installed already, which *might* be an issue. I had 1.9.x working fine and was using this to try to install 1.8.7 under rvm, but I just went with 'rvm use system' so am now in the "gave up" crowd. – JohnMetta Aug 01 '12 at 17:22
  • Fair enough. Perhaps I'll try and report back. – briangonzalez Aug 01 '12 at 17:28
  • Strongly recommend against posting links that point directly to downloadable files. Usuers almost always need the context that you're skipping past. In this case, you've linked a particular build that was current when you posted it, but is now obsolete. – Isaac Rabinovitch Jul 01 '13 at 02:11
  • @IsaacRabinovitch StackOverflow is full of obsolete/stale information. We as readers need to come ready to recognize that nearly year-old answers may have stale information. My two cents. – briangonzalez Jul 01 '13 at 16:08
  • @briangonzalez Sure, all information gets stale eventually. That doesn't mean we shouldn't do our best to provide information in a form with a longer shelf life. It's only fair to other users that you take the time to find a link that will still be useful years from now, as opposed to one that's guaranteed to be useless in 6 months. That's doubly true when you directly link a package file, bypassing the page that describes it. – Isaac Rabinovitch Jul 01 '13 at 20:04
3

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.

stites
  • 4,903
  • 5
  • 32
  • 43
bbaassssiiee
  • 6,013
  • 2
  • 42
  • 55
1

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

nbs
  • 573
  • 1
  • 6
  • 15
1

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.

DaveR
  • 9,540
  • 3
  • 39
  • 58
Pongthep
  • 11
  • 1