Mac OS X: Install GCC Compiler with Xcode

See all Apple macOS/Mac OS X Unix related FAQs
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
Difficulty level Easy
Root privileges Yes
Requirements Mac OS X Mountain Lion
Est. reading time 2 minutes
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:

$ $

This entry is 5 of 13 in the Linux GNU/GCC Compilers Tutorial series. Keep reading the rest of the series:
  1. Ubuntu Linux Install GNU GCC Compiler and Development Environment
  2. Debian Linux Install GNU GCC Compiler and Development Environment
  3. CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools
  4. Download and Install C, C++ Compiler on Red Hat Enterprise Linux 5 (RHEL)
  5. Mac OS X: Install GCC Compiler with Xcode
  6. Where is My Linux GNU C or GCC Compilers Are Installed?
  7. HowTo: Compile And Run a C/C++ Code In Linux
  8. RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers
  9. HowTo Compiling C Program And Creating Executable File Under a Linux / UNIX / *BSD
  10. How To Install ncurses Library on a Linux
  11. Linux Find Out What Compilers Are Installed or Available On The System
  12. Linux Find Out GNU gcc Compiler Version Used To Compile Running Kernel
  13. Howto see output of C program in Linux or UNIX

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

28 comments… add one
  • Daniyah Jun 4, 2014 @ 10:38

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

    please help me.

    • Ryan Jan 24, 2015 @ 20:25

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

  • vanessa Jul 14, 2014 @ 23:04

    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

  • Shubham Jain Jul 22, 2014 @ 2:41
    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"
        export MACOSX_DEPLOYMENT_TARGET=10.9
        /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)


  • gina4eva Sep 5, 2014 @ 18:14

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

  • billy Sep 19, 2014 @ 13:58
    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
  • fred Feb 12, 2015 @ 23:02

    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.

  • Zahra Mar 3, 2015 @ 18:57

    Does it work on Mac air?

  • jane May 30, 2015 @ 10:50

    i can’t find command line tools on my xcode. >< my xcode version is 6.3.2

    • DP Jun 1, 2015 @ 7:45

      Open the Terminal app and cd to /Applications/ path:

      cd /Applications/

  • Brian Jul 29, 2015 @ 15:04

    HELP; In the downloads, I don’t see command line tools.

  • Nam Nov 22, 2015 @ 4:35

    Please help

    i have the x-code and when i typed gcc –version it gave
    ‘Configured with: –prefix=/Applications/ –with-gxx-include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 7.0.0 (clang-700.1.76)
    Target: x86_64-apple-darwin14.5.0
    Thread model: posix’
    and when i type ls -l /usr/bin/gcc
    ‘-rwxr-xr-x 1 root wheel 14160 Sep 28 2014 /usr/bin/gcc’
    so i cant go beyond this. Can someone please help?

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.