11

I just got a Mac and I'm a complete newbie, so this may be kind of a really easy question, but I wasn't able to solve it with Google or F1.

I was trying to run a C program from the Terminal that comes with mac, but when I used gcc test.c, it said -bash: gcc: command not found. I looked up the error on Google and discovered that I needed to download Xcode. I did that and installed it (I think, after all it runs), but I still don't have gcc in my Terminal. What can I do?

1
  • Note that from Xcode 5 Xcode and command line tools don't include gcc or a wrapper just clang
    – mmmmmm
    Commented Jan 29, 2014 at 16:16

3 Answers 3

23

Great question — this recently changed, so I suspect many other people are wondering the same thing.

In the latest version of Xcode, the command line tools are distributed as a separate package. Luckily they're very easy to install:

  • Open Xcode, and open the Preferences window (+,).
  • Switch to the Downloads tab.
  • Click "Install" (or "Update") next to "Command Line Tools". You can also configure automatic updates, and additional Xcode components.

Note: since these tools are actually a completely separate package, you can install the command line tools without installing Xcode, if you don't need Xcode and want to save some disk space. They can be downloaded separately from the Apple developer site.

2
  • 1
    I wish I'd know you could install them separately, I never would have wasted the space downloading and installing Xcode. Thanks! Commented Mar 23, 2012 at 18:43
  • I know exactly what you mean. I spend a lot of time working on a Mac Book Air. Xcode uses up a significant portion of my disk. Commented Jul 25, 2013 at 5:25
5

If the command-line tools are all you need and you don’t really need Xcode, then there’s a much more efficient way to install these tools that doesn’t require you to download multiple gigabytes of data.

Simply download the “Command Line Tools” package from Apple Developer (free account required; you can use your Apple ID). As of this writing, the package is named “Command Line Tools for Xcode - Late March 2012”. It’s a 171.70 MB disk image, which pales in contrast to the 4+ GB Xcode download.

Note that, if you’ve already installed Xcode, you’ll want to uninstall it before installing the Command Line Tools.

1

This is the expected behaviour, Xcode now uses LLVM as the default compiler. Starting with Xcode 4.3 gcc is not included anymore, distributed builds is not available anymore either.

If you want gcc you will have to download the separate package named "Command Line Tools for Xcode" from Xcode as described in this answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .