How to install gcc compiler on Mac OS X

Often times, you need c or gcc compiler to compile open source projects in Mac OS X. The problem is Mac OS X doesn’t install the gcc compiler by default.

If you try to install or compile some projects that required c/gcc compiler, following errors message will be logged :


configure: error: C compiler cannot create executables

configure: error: no acceptable C compiler found in $PATH

In terminal, type “gcc“, you will get message “command not found”.


$ gcc
-bash: gcc: command not found

Solution

To install gcc compiler on Mac OS X, you need to download and install “Command Line Tools for Xcode”, which is available in Apple’s developer page. See following steps :

1. Register Apple Developer Account

Access Apple’s developer page, to process on the download, you need to register an Apple account, it’s free, but need to spend few minutes to fill in the survey.

2. Command Line Tools for Xcode

In Apple developer page, “Developer Tools” category, find “Command Line Tools for Xcode“, choose your version and click on the xx.dmg file (file size is 100mb ++) to start the download.

Apple Developer Download Page

3. Installation

After .dmg file is downloaded, a small dialog will be prompted and show you this file – “Command Line Tools.mpkg“, just double click on it, follow the wizard guide to complete the installation.

install command line tools
install command line tools

4. Verification

After installation is completed, run “gcc -v” in terminal again. If everything fine, following output will be displayed.


mkyong$ gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: {ignore long text…}
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)

Done, the gcc version 4.2.1 is installed on Mac OS X successfully.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Porque?
Guest
Porque?

This is wrong. This gcc is simply a facade for Clang + LLVM. Get your facts right before you write a freaking blog, you imbecile.

wer
Guest
wer

although this is a little harsh on the author, it’s exactly true

Max Weis
Guest
Max Weis

I just tried the gcc installer (without xcode), works well:
https://github.com/kennethreitz/osx-gcc-installer

Kkuja
Guest
Kkuja

Oh for * sake. I wanted to install GCC, not xcode! FYI, xcode is not gcc. Also, xcode doesn’t contain gcc, but LLVM. There is slight, but definite difference.

anonymous
Guest
anonymous

it helps. thanks

Letícia Conceição
Guest
Letícia Conceição

Thanks! :)

Jorge Hernandez
Guest
Jorge Hernandez

I did this, gcc gives me its version info, but I still get the message “C Compiler cannot create executables”

Do I need to do anything else to get rid of that message?

Prudhvi Samayamanthula
Guest
Prudhvi Samayamanthula

my lap is 10.9 version and it says this is only downloadable for 10.7 or before

Apurv Singh
Guest
Apurv Singh

Thanks a lot!. It was a great help. :)

Myrtille
Guest
Myrtille

Thank you for this very clear explanation

Student
Guest
Student

Thank you so much! I am a student. They asked us to write a C program without explaining how to set up the environment=) This was very helpful=)

Gcherkos
Guest
Gcherkos

tnx nd is important!
G

Rene Z
Guest
Rene Z

Great help, I was getting stuck and this was amazing!

Tristan Xu
Guest
Tristan Xu

Helped!

Tanvi
Guest
Tanvi

Thanks a lot….i was successful in downloading the gcc on my mac.
thanks for sharing the thoughts, it was very helpful :) :) .

darrennie
Guest
darrennie

Thanks a bunch, yet again.

EdvanSousa
Guest
EdvanSousa

valeu irmão! funcionou pra mim muito bem! thanks a lot! works great!

EWKY
Guest
EWKY

thanks so much, this got me out of a jam!

trackback
Step 1: C/C++ Intro | Make Tech EZ

[…] article How To Install Gcc Compiler On Mac OS X provides a good walkthrough to install GCC on […]

Beckah
Guest
Beckah

“Ayn:~ R$ gcc -v
Configured with: –prefix=/Developer/usr –with-gxx-include-dir=/usr/include/c++/4.2.1
xcrun: Error: failed to exec real xcrun. (No such file or directory)”

Andreas Daskalopoulos
Guest
Andreas Daskalopoulos

Thanks!

Jia En
Guest
Jia En

Hi, thanks for writing this post. I followed your instructions but command line tools won’t install properly.

I got this message instead when the installer told me installation had failed: “The installer can’t locate the data it needs to install the software. Check your install media or Internet connection and try again, or contact the software manufacturer for assistance.”

Do you have any idea what the problem might be?

Sincerely
Jia En

Neeraj Pradhan
Guest
Neeraj Pradhan

I am getting this msg at the “Apple Developers Page”We appreciate your patience as we work to bring our developer services back online. Certificates, Identifiers & Profiles, software downloads, and other developer services are now available. What is the alternative. Is there one??

Neeraj Pradhan
Guest
Neeraj Pradhan

I am getting this msg at the “Apple Developers Page”We appreciate your patience as we work to bring our developer services back online. Certificates, Identifiers & Profiles, software downloads, and other developer services are now available. What is the alternative, is there one??

Jonas
Guest
Jonas

Hi mkyong,

I am having a problem with command tools, i am using mac 10.8, downloaded the command tool, install it.The installation goes step by step as described. But when installation finish, it treats the software as an external drive, or doesn’t install it in “machintosh HD” as it is supposed to. As a result you can’t find command tool if you run “gcc-v”.I checked if there is any similar problem, but i don’t see anywhere. Any idea why?

Sreejith
Guest
Sreejith

Actually, you’re explaining the process of installing llvm-gcc which is actually not the actual gcc. Its a modified version made by Apple to compile C/Obj-C programs.

Although this is fine for most purposes, some other tools (I think its Ruby, not sure) require the original gcc package. Not the llvm one.

Fabian Thiem
Guest
Fabian Thiem

Thanks!

vinu
Guest
vinu

thanks!

Gargee
Guest
Gargee

Thanks a ton ..all your tutorials are excellent…and Big Thanks !

Stuart
Guest
Stuart

Thanks! Instructions worked perfectly.

Mareo Raft
Guest
Mareo Raft

When I search “command line” as you did, there is no “Command Line Tools for Xcode” listed. In fact, my categories are different from yours also. The categories on the left-hand bar say Platform: Safari, OSX, iOS, Java, General; and Type: Guide, Sample Code, Reference, General.

The closest thing that sounds like what I’m looking for is “Quartz Composer CommandLineTool”, but that isn’t a package. Please help, thank you,

Mareo

Ryan Edwards
Guest
Ryan Edwards

Mareo,

Your not supposed to search for command line. All he said was to go to https://developer.apple.com/downloads/index.action
and download command line tools for xcode from the list on that page… do not search for command line

ces
Guest
ces

Same exact issue here – no Command Line Tools for Xcode are available in the list. And his screenshot shows the ‘command line’ string being searched on. That should have no bearing on whether it’s in the list or not. Why would it show for some people and not others I wonder?