Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

gcc: command not found error (this still haunts me, please help!)

Hello all,

I am trying to compile C files using terminal and the gcc command. I have XCode installed and can run a simple program no problem in XCode, but when I try compiling using the gcc command in terminal I get this error:

-bash: gcc: command not found

I know this is a common newbie mistake and is usually the result of improper XCode installation or not having the PATH set correctly. The odd thing is, a few months ago I was using Terminal to compile/run C files with no issue. Since then, I recently began programming using Java. I installed Eclipse and was using it to compile/run java programs, so my guess is that somehow having both Xcode and Eclipse installed together is causing the issue. I originally installed XCode by downloading it directly from the developer.apple.com/tools/xcode/ link and like I said, had no issues.

So the question is, do I really need to uninstall, re-download, and re-install Xcode again? I'd prefer to not mess around with the PATH either since I've never done this before and I previously had no issue six months ago. If I do need to download and re-install, what is the proper way to do this (while saving my old projects)? Thank you for the help

-Steve

Powerbook G4 (yup, the old one), Mac OS X (10.5.8)

Posted on Nov 29, 2009 7:14 PM

Reply
Question marked as Best reply

Posted on Nov 29, 2009 9:43 PM

What is your current PATH setting? It sounds likely to be something wrong
with the current setting. It is possible the installation of Eclipse has
broken the previous setting.

Dave
14 replies

Nov 29, 2009 11:05 PM in response to Steven Dunn2

Hi Steven -
There are a few simple problems to rule out before doing anything as drastic as re-installing the dev tools. Xcode upgrades have been known to affect access to gcc from Terminal, and I wouldn't be very surprised if the Eclipse installer was capable of that as well.

I'm not very good at unscrambling this kind of installation problem, but until one of our more experienced Mac developers comes along I might be able to give you some ideas.

I have an iMac with OS X 10.5.8, and here's what the Terminal environment looks like:
rays-imac:~ Ray$ echo $MACHTYPE
i386-apple-darwin9.0

rays-imac:~ Ray$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:.

rays-imac:~ Ray$ whereis gcc
/usr/bin/gcc

rays-imac:~ Ray$ ls -ltr /usr/bin/gcc*
-rwxr-xr-x 1 root wheel 93088 Feb 5 2009 /usr/bin/gcc-4.0
-rwxr-xr-x 1 root wheel 105680 Jul 6 19:53 /usr/bin/gcc-4.2
lrwxr-xr-x 1 root wheel 7 Oct 5 22:54 /usr/bin/gcc -> gcc-4.0

rays-imac:~ Ray$ ls -ltr /usr/bin/g++*
-rwxr-xr-x 1 root wheel 93088 Feb 5 2009 /usr/bin/g++-4.0
-rwxr-xr-x 1 root wheel 105680 Jul 6 19:53 /usr/bin/g++-4.2
lrwxr-xr-x 1 root wheel 7 Oct 5 22:54 /usr/bin/g++ -> g++-4.0

If your PATH is correct, the next thing I would check is the gcc symbolic link. I think we've seen this disappear in the past. In fact you might just type gcc-4.0 right away and see if it's found.

If none of the above is helpful, be sure to search in this forum for related threads. There have been quite a few recently, though many of those have been specific to 10.6.
\- Ray

Nov 30, 2009 12:55 AM in response to RayNewbie

Thanks for the responses, echo $PATH returns: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

So that looks the same as yours. I have a PowerPC Powerbook and I've never "upgraded" XCode, I downloaded my version about 6 months ago. whereis gcc returns nothing and the other ls -ltr /user/bin/ don't return anything either. To be honest, I'm very inexperienced (started programming as a student in May), but I'm capable of typing in simple terminal commands 🙂. Another thing to note is that I'm not sure if Eclipse actually uses an "installer" or if you just unzip an archive, and run the application. I looked up Eclipse uninstallation and that's what I saw.

Nov 30, 2009 12:50 PM in response to etresoft

etresoft wrote:
Steven Dunn2 wrote:
ls -ltr /user/bin/ don't return anything either.


Try: ls -ltr /usr/bin


Sorry, that was a typo, I tried ls -ltr /usr/bin/gcc* and ls -ltr /usr/bin/g++* and it returns "No such file or directory." Using just "ls -ltr /usr/bin" returns a bunch of stuff, but I didn't see any folders with /gcc or /g++.

Typing "xcode-select -print-path" returns:
/Developer

Sounds like that's in order. Oddly enough, if I navigate to MyHD/Developer/usr/bin (through finder or with the command cd /Developer/usr/bin), I can see the gcc, g++, and all other executable files (they look like aliases).

Nov 30, 2009 1:14 PM in response to Steven Dunn2

Steven Dunn2 wrote:
etresoft wrote:
Steven Dunn2 wrote:
ls -ltr /user/bin/ don't return anything either.


Try: ls -ltr /usr/bin


Sorry, that was a typo, I tried ls -ltr /usr/bin/gcc* and ls -ltr /usr/bin/g++* and it returns "No such file or directory." Using just "ls -ltr /usr/bin" returns a bunch of stuff, but I didn't see any folders with /gcc or /g++.

Typing "xcode-select -print-path" returns:
/Developer

Sounds like that's in order. Oddly enough, if I navigate to MyHD/Developer/usr/bin (through finder or with the command cd /Developer/usr/bin), I can see the gcc, g++, and all other executable files (they look like aliases).


FYI, the alias 'gcc' looks like this on my system:

ls -l /usr/bin/gcc
lrwxr-xr-x 1 root wheel 7 Nov 18 21:50 /usr/bin/gcc -> gcc-4.2


-- an additional ls -l /usr/bin/gcc* lists gcc, gcc-4.0, and gcc-4.2, all inside "usr/bin" inside "Developer". The Finder shows them with the correct icons -- regular for the numbered versions, an alias for "gcc". Is yours different?

Nov 30, 2009 2:29 PM in response to etresoft

Jongware wrote:
an additional ls -l /usr/bin/gcc* lists gcc, gcc-4.0, and gcc-4.2, all inside "usr/bin" inside "Developer". The Finder shows them with the correct icons -- regular for the numbered versions, an alias for "gcc". Is yours different?


No, mine look the same as you describe.

etresoft wrote:
Whatever the reason, you have a "custom" Xcode install. Follow the directions in this thread to make it useable or reinstall it.


I only have one version of Xcode installed (3.1.2), the gcc commands were working in terminal 6 months ago. I haven't touched Xcode since then or installed anything new except Eclipse. That said, I had previously read that thread you linked, and I tried using

export PATH=/Developer/usr/bin:${PATH}
export MANPATH=/Developer/usr/share/man:${MANPATH}

Using gcc then attempted to compile my .c file but gave a bunch of errors (the same program compiles without errors in xcode). I don't want to alter the .bash_profile because I don't know how and I don't want to create any new issues. I suppose this leaves me only with the option of reinstalling. Right now, however, I can still compile and run programs fine in Xcode, just not in Terminal, so I guess I'll have to decide whether it's worth my time to reinstall. I was hoping there was an easier way out.

Nov 30, 2009 2:52 PM in response to Steven Dunn2

(for whatever reason I can't edit my own post, sorry for the double post)...

Anyway, If this is my only option, is this the proper way to uninstall Xcode?:

sudo <Xcode>/Library/uninstall-devtools --mode=all

Also, where can I re-download Xcode for PowerPC (10.5.8)? The version on http://developer.apple.com/technology/xcode.html says an Intel Mac is required. Thank you.

Dec 1, 2009 6:31 PM in response to jpimbert

Thanks for the link. Ok, I've uninstalled.
"sudo <Xcode>/Library/uninstall-devtools --mode=all" didn't work for some reason, but this did:
"sudo /Developer/Library/uninstall-devtools --mode=all"

Anyway, I'm ready to re-install. The only odd thing is the installer says "Custom Install." Wasn't I trying to avoid a "custom" install? Perhaps it's because I downloaded it instead of using the installer on the Panther CD, but I see no option for a "Basic" installation. Also, do I need both "System Tools" and the "UNIX Development Support?" (I need all the HD space I can get). Thanks again.

Dec 1, 2009 11:47 PM in response to jpimbert

I went ahead and installed Xcode with the UNIX development support. I'm happy to announce that everything seems to work perfectly again 🙂. It's entirely possible that I didn't install the development support the first time I installed Xcode to try and save space. I did most of my programming on a linux server at school using ssh from terminal, so perhaps gcc was working because I was using the commands on the linux server. I thought I was using them from a new terminal shell on my system, but maybe not. As I mentioned, it's been about 6 months so I may have just forgotten.

Either way, thanks for being patient, you have all been very helpful!

gcc: command not found error (this still haunts me, please help!)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.