Mac OS X: Install GCC Compiler with Xcode

by on June 9, 2013 · 22 comments· LAST UPDATED January 15, 2014

in , ,

I have Mac OS X Mountain Lion. I need to compile a few apps and Perl modules. I already installed Xcode from app store but I'm unable to find gcc compiler or make command. How do I install gcc on Mac OS X 10.8.x?

Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsMac OS X Mountain Lion
Estimated completion timeDepends on the internet speed
Xcode includes command line development tools such as gcc and friends.

Step #1: Install Xcode on a Apple Mac OS X

First, make sure Xcode is installed. If it is not installed on OS X, visit app store and install Xcode.

Fig.01: Make sure Xcode developer tools are install OS X

Fig.01: Make sure Xcode developer tools are install OS X

Step #2: Install gcc/LLVM compiler on OS X

Once installed, open Xcode and visit:

Xcode menu > Preferences > Downloads > choose "Command line tools" > Click "Install" button:

Fig.02: Installing gcc compiler on Mac OS X

Fig.02: Installing gcc compiler on Mac OS X

Xcode will download package and install copies of the core command line tools and system headers into system folders, including the LLVM compiler, linker, and build tools.

Step #3: Verification

Open a terminal app and type the following commands:
$ gcc --version
$ whereis gcc
$ whereis make

Sample outputs:

Fig.03: Verify gcc compiler installation on Mountain Lion OS X

Testing sample "Hello world" C program

Create a text file called a.c as follows using a text editor such as vi or cat command:

/* a.c - demo for os x */
int main(void){
 printf("Hello world\n");
 return 0;

To compile, enter:
$ make a
Run it as follows:
$ ./a
Sample outputs:

Fig.04: Compiling and running sample

Fig.04: Compiling and running sample "Hello world" C program on Mountain Lion 10.8.4

See also

And, there you have it, the gcc version 4.2.1 installed and working correctly on the latest version of Mac OS X 10.8.4. In Apple's version of GCC, both cc and gcc are actually symbolic links to the llvm-gcc compiler. Similarly, c++ and g++ are links to llvm-g++. For more information and examples see the following man pages:

$ man gcc
$ man make

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 22 comments… read them below or add one }

1 meow June 9, 2013 at 2:19 pm

There is no need to install huge xcode consumes gigabytes of disk space (if you are not a apple developer), just go to the apple’s developer page and download the “command line tool for xcode” package and install it, that would be just sufficient.


2 ydk2 June 22, 2013 at 7:39 am

Isn’t GCC is LLVM with GCC support and many automake, m4 etc… project is not enable to build.


3 Mustafa July 30, 2013 at 9:51 pm

thank u very very very much you are really clever


4 Reva September 18, 2013 at 2:55 am

THANK YOU SO MUCH!!! Everything else I tried didn’t seem to work. Finally this did!!!!


5 john September 27, 2013 at 10:59 pm

Thank you very much. It worked.


6 Asaf November 6, 2013 at 4:09 pm

I installed the Xcode Command Line Tools, and when I try to find gcc in the terminal
tell me this:

new-host:~ asaffeldman$ $gcc –version
-bash: –version: command not found

?? help


7 Martin December 13, 2013 at 3:50 pm


gcc --version

with 2 dashes and no $ in front of it
hope it helps!


8 Mohamed Magdy November 30, 2013 at 8:39 am

I anderstand


9 Simo December 18, 2013 at 1:54 pm

Clear , efficient , thanks !


10 ydk2 January 15, 2014 at 2:34 pm

I have GCC 4.8.1 with x86, x86_64 and PPC on Lion with ObjC, C/C++11, Fortan, Ada Go support.
And now I can compile PHP, WxWidgets, QT and many other source without problems like on Apple Clang vesion. In xcode too.
Gcc builded with llvm-gcc-4.2.


11 viky March 8, 2014 at 1:02 pm

i m doing the c programming on terminal my keyword is not highlited by compiler,
strstr function is not working why plz resolve my problm


12 Daniyah June 4, 2014 at 10:38 am

when I typed make a I got this message:
make: *** No rule to make target `a’. Stop.

please help me.


13 Ryan January 24, 2015 at 8:25 pm

I got the same error when I didn’t spell the filename with the exact case.


14 vanessa July 14, 2014 at 11:04 pm

Hi , I installed xcode and command line tools just as you said but when I try the command gcc –version I get this error
Error: could not stat active Xcode path ‘/Volumes/Xcode/’. (No such file or directory)

Is my xCode in the wrong place? It’s installed and under Applications, please help


15 Shubham Jain July 22, 2014 at 2:41 am
Ld /Users/shubhamjain/Library/Developer/Xcode/DerivedData/Production_rates-eqoyfionzpuxskflgywwzthhilri/Build/Products/Debug/Production\ rates normal x86_64
    cd "/Users/shubhamjain/Documents/Xcode/Production rates"
    /Applications/ -arch x86_64 -isysroot /Applications/ -L/Users/shubhamjain/Library/Developer/Xcode/DerivedData/Production_rates-eqoyfionzpuxskflgywwzthhilri/Build/Products/Debug -F/Users/shubhamjain/Library/Developer/Xcode/DerivedData/Production_rates-eqoyfionzpuxskflgywwzthhilri/Build/Products/Debug -filelist /Users/shubhamjain/Library/Developer/Xcode/DerivedData/Production_rates-eqoyfionzpuxskflgywwzthhilri/Build/Intermediates/Production\\\ rates.LinkFileList -mmacosx-version-min=10.9 -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/shubhamjain/Library/Developer/Xcode/DerivedData/Production_rates-eqoyfionzpuxskflgywwzthhilri/Build/Intermediates/Production\\\ rates_dependency_info.dat -o /Users/shubhamjain/Library/Developer/Xcode/DerivedData/Production_rates-eqoyfionzpuxskflgywwzthhilri/Build/Products/Debug/Production\ rates
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)



16 gina4eva September 5, 2014 at 6:14 pm

I don’t have the Command Line option in my preference. Help!


17 billy September 19, 2014 at 1:58 pm
Configured with: --prefix=/Applications/ --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-darwin13.4.0
Thread model: posix


18 fred February 12, 2015 at 11:02 pm

I have xcode. I see gcc on my mac: Macintosh/Developer/usr/bin/gcc-4.0
But as soon as I type gcc whatever in the terminal because I want to compile a file called hpgl2eagle1.c to be able to use it, it outputs an error: gcc command not found.


19 nixCraft February 13, 2015 at 7:00 am

Set PATH variable on your OS X. See: “Mac OS X: Set / Change $PATH Variable” for more info.


20 fred February 13, 2015 at 10:39 am

It worked. Thank you very much!


21 Zahra March 3, 2015 at 6:57 pm

Does it work on Mac air?


22 nixCraft March 4, 2015 at 12:14 am



Leave a Comment

Tagged as: , , , ,

Previous Faq:

Next Faq: