How to test if gcc is installed?

9

How can I find out if I have gcc installed on my machine?

I am trying to run CodeRunner, but it isn't responding. I know you have to have gcc installed in order for it to work properly. I do have Xcode 4.0.2 installed (from what I've read, if Xcode is installed then you already have gcc).

willis0924

Posted 2011-04-30T02:25:28.230

Reputation:

Answers

8

  1. Type gcc at the Terminal prompt. If it says "command not found", you don't. Otherwise, you do.
  2. If that fails, then install from your OSX CD.

Ernest Friedman-Hill

Posted 2011-04-30T02:25:28.230

Reputation: 855

4Technically, that is testing to see if gcc is in his PATH. Typing gcc could fail even if it is installed. – None – 2011-04-30T02:31:27.803

@objectiveGeek - Yes, but if it's not in his $PATH it's not going to be useful, as most scripts that rely on it being "installed" will probably rely on it also being in $PATH and thus callable as gcc instead of /my/dumb/install/location/gcc – None – 2011-04-30T02:33:27.987

@Ernest: It gave me 'no input files'. Does this mean its installed. I'm assuming yes? – None – 2011-04-30T02:36:10.503

@wilis0924: Yes. Also try gcc -v to get the installed version number. – Drew Hall – 2011-04-30T02:37:56.247

@Chris Installing gcc under /usr/bin is optional in Xcode’s installer. – None – 2011-04-30T02:38:15.440

@Drew Hall: 'version 4.2.1' is that up to date? – None – 2011-04-30T02:42:55.943

@Bavarious - You can install it wherever you want, but if it's not in your $PATH it's going to break most outside scripts (which will expect it to be there.) – None – 2011-04-30T02:46:45.480

@Chris Lutz, ObjecctiveGeek is correct as this is a bad answer because it equates not finding a program with not having the program. I, for example, am having a problem where I need gcc-4.7, but synaptic is telling me I already have it, even though I don't know where it is. – puk – 2013-10-25T09:42:36.803

4

You could just try to see if a gcc executable is present. Try:

ls /usr/bin/gcc*

highBandWidth

Posted 2011-04-30T02:25:28.230

Reputation: 507

Better with whereis gcc or which gcc. – jweyrich – 2011-04-30T02:38:58.083

which only works if the PATH is correctly configured. – highBandWidth – 2011-04-30T02:39:59.807

Yet, if you don't have /usr/bin in your PATH, your Mac OS is likely to be broken. – jweyrich – 2011-04-30T02:42:10.377

If someone messed up the .bash_profile for the particular user, the PATH could be messed up while the system is ok. – highBandWidth – 2011-04-30T02:45:10.137

I, for one, have gcc-4.7-base installed (according to synaptic package manager) but whereis/which can not find it – puk – 2013-10-25T09:44:46.300

3

You can use "locate gcc" to find all filenames with gcc in them.

Xenoactive

Posted 2011-04-30T02:25:28.230

Reputation: 992

3

Try any terminal command, like:

$ gcc --help

If gcc isn't installed, you will often see a message with a "how to install it" note, complete with the package manager's command.

141.80

Posted 2011-04-30T02:25:28.230

Reputation: 89

0

On Terminal type

gcc -v

You will get something like below

Using built-in specs.
 ......
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

This will show you version of GCC installed on your machine. If gcc is not installed then this command will not work as above

silwar

Posted 2011-04-30T02:25:28.230

Reputation: 101

Can you add some more explanation of what this output means. – ChrisF – 2013-02-14T11:42:27.300

Please check edited part – silwar – 2013-02-14T11:56:48.580