45

I've googled the hell out of it, and it seems like there is no way to install gcc on OS X without installing Xcode (which takes at leats 1.5GB of space). All I need is gcc and none of the other junk that comes with Xcode. And at this point, I'll take any other kind of C compiler.

I know I could simply install Xcode, but that is beside the point since I neither have my original installation disc nor a quick internet connection.

So... does anyone have any suggestions?

EDIT: Sorry if I was unclear, but I need the headers as well. I'm currently installing gcc4 via fink and it's downloading the shared libraries as well. I'll update on the progress.

EDIT 2: Ok, so I successfully installed gcc using fink. BUT, it's pretty much useless: "error: C compiler cannot create executables". After googling around, I found that not having Apple's Developer Tools installed is the cause of the error. Probably because I need all the libraries, headers, etc that are only available through Xcode.

aryo
  • 695
  • 2
  • 7
  • 13
  • Do you want a full environment, i.e. headers etc, or _just_ a c compiler? – freespace Sep 22 '08 at 14:14
  • 1
    I still wonder if you ever managed to do it somehow. Not for gcc, tho, I'm trying to install another Xcode tool: FileMerger - http://superuser.com/questions/117621/how-to-merge-and-not-replace-folders-when-copying-on-mac – cregox Mar 11 '10 at 00:28
  • 1
    You can download just the gcc at: http://opensource.apple.com/release/developer-tools-40/ – fooMonster Jul 19 '11 at 12:23
  • Now there is this option. http://kennethreitz.com/xcode-gcc-and-homebrew.html Command line support for xcode. – Amir Raminfar Feb 17 '12 at 03:07

10 Answers10

36

Checkout command line tools for Xcode from apple. It's official support from apple to only create the command line tools.

Amir Raminfar
  • 33,777
  • 7
  • 93
  • 123
  • 4
    This definitely seems like the most relavent answer now - thanks. – lashleigh Apr 13 '12 at 19:31
  • This is awesome and perfectly answers the question! Thanks – wap26 Jul 12 '12 at 07:00
  • 1
    Only works for OS 10.7.3+. If you have an older installation you will need to use the [osx-gcc-installer](https://github.com/kennethreitz/osx-gcc-installer) (or other) solution. – Peter Gluck May 06 '13 at 23:11
  • The answer is correct, but if you already had Xcode at some point and deleted it to save some precious space, you might need to reset the settings using the command and the command line tools install: sudo xcode-select -r – Romulo Diniz May 19 '23 at 02:15
31

Try the osx-gcc-installer on github.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
ergosys
  • 47,835
  • 5
  • 49
  • 70
  • 2
    That project (osx-gcc-installer) has worked great for me, and is more than adequate for building with Homebrew. Two things that his FAQ doesn't make clear: You can safely install Xcode over osx-gcc-installer if it doesn't work for you, and if you already have Xcode installed, you can remove it before/after installing osx-gcc-installer. – oasisbob Aug 13 '11 at 22:35
  • 4
    This project is flawed in [serious ways](http://librelist.com/browser//homebrew/2011/8/11/gcc-without-xcode-script/#39215709e8fd9052f361413d9b4a59a3) and will almost certainly be pulled. – Adam Lassek Aug 16 '11 at 05:30
  • 1
    I really suggest using the project that the writer linked to by Adam Lassek created. Here’s a direct link, for posterity: http://git.io/xcode – ELLIOTTCABLE Oct 14 '11 at 02:28
6

I've been doing this for a long time, and I've done things like this, and I've concluded it's simply never worth doing. :-(

The reason is that no one expects you to do such things, so there are assumptions all over the system that "everything" is there. You might not run into this today - or worse, you might not even realize later that this is the cause of your issues.

Instead of wasting your smart time on things like this which don't actually produce any working code you can use, following the approved method, run the download overnight, and spend your time instead on planning and writing the top-level code (you shouldn't need a compiler for that anyway!)

Tom Swirly
  • 2,740
  • 1
  • 28
  • 44
3

I'm fairly certain that this is not possible. However, I'm also not sure if you need the whole developer suite to get the developer tools installed. Quite a few tools get installed along with XCode that might be optional. However, I think you're out of luck for not needing to bite the bullet and use wget or DownThemAll or some other download manager that will let you slowly download the developer tools in chunks.

Whenever I install OS X I install the developer tools as a rule, just because it opens up the world of available software tremendously. Perhaps you should consider doing this in the future as well.

Tim Visher
  • 12,786
  • 16
  • 58
  • 66
2

The first thing you want to try is called Pacifist - what Pacifist lets you do is to open a large package (such as XCode) and to access parts of it directly. I'm pretty sure you'll be able to find a smaller package inside the XCode package that just has gcc.

HOWEVER it's not clear to me that this is the best route. If you are planning to do Cocoa or Carbon developing I strongly suggest installing the entire package because you will need all the documentation and headers. If you're only planning on doing command-line stuff, you still may find you need to poke around inside XCode to identify all the packages you will need - things such as libraries, headers, man pages and so on.

All in all you're probably still better off installing the whole thing - if HD space is really tight (because you're on a tiny old iMac for example) then look at tools like Monolingual - Monolingual removes all the international support from all the various OS X applications, which can easily reduce the size of an application by 50%.

Mike Heinz
  • 1,787
  • 1
  • 17
  • 23
  • 1
    I believe you are correct as well, sir. By the way, thanks for recommending Monolingual. – aryo Sep 22 '08 at 17:33
1

There's fink and MacPorts, if you want an easy installer/updater.

eduffy
  • 39,140
  • 13
  • 95
  • 92
  • Not macports, which requires Xcode, since it compiles every package. See http://www.macports.org/install.php . – freespace Sep 22 '08 at 13:42
  • 1
    No, fink can be restricted to binary only, so it doesn't require a working compiler unless you want to go outside binary packages. Whether or not gcc is available as a binary package, I don't know. – freespace Sep 22 '08 at 13:53
  • 1
    http://pdb.finkproject.org/pdb/package.php/gcc42 - looks like a binary version is available for OS X 10.5. – Daniel James Sep 22 '08 at 13:59
  • 2
    Why does this have 3 points? Not to put to fine a point on it, the answer is quite wrong. Both Macports and Fink list XCode as a pre-requisite for installation: http://www.macports.org/install.php http://www.finkproject.org/doc/bundled/install-first.php – Mike Heinz Sep 22 '08 at 14:43
  • 1
    Yes, the docs say that, but I can tell you _from experience_ fink _can work without a compiler_. As it says on the downloage page: "You may find that only using binary packages limits the utility of Fink... To build packages from source, you will need to install the Developer Tools..." – freespace Sep 22 '08 at 15:02
  • This is the same as homebrew "can work without a compiler"... in reality, it is a pain in the as$. – Dalibor Filus Mar 13 '12 at 13:08
0

Install the GCC package from the Packages directory in Xcode's disk image and you'll have just GCC. Note that of course you won't have autotools or other standard build tools, for which you will have to install more packages from that folder.

millenomi
  • 6,569
  • 4
  • 31
  • 34
0

I found this googling around that appears to install it without XCode.

Brian
  • 5,826
  • 11
  • 60
  • 82
  • 1
    ... You needed to read a little further in that article - that was an article on how to compile and install a newer GCC on top of the GCC that Apple was shipping in 2002, it does not permit installing a compiler without XCode. – Mike Heinz Sep 22 '08 at 14:37
  • +1 because it helped me, I was googling "gcc on osx" and found this. I want to get gcc 4.6 or 4.7 so I can use c++11 features on OSX – matiu Jan 09 '12 at 01:34
0

yes i could do it with port but you need at least to accept the code license.

Sherif O.
  • 506
  • 4
  • 15