Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm running centOS 6.3 which comes with gcc 4.4.6 and I installed gcc 4.6.3 using these instructions.

But when I type gcc -v it still says gcc 4.4 is the version I'm using. The newer version is under /opt/gcc-4.6.3.

When I run a make command do I have to specify a path to use the newer gcc? If so how do I do this, or can I replace the older version fully with the newer one? Thanks in advance.

share|improve this question
add comment

2 Answers

You can tell make which program to use for C compiles by setting the environment variable CC, and similarly CXX for C++. (That's assuming that you use the default rules or at least copy them. If you write your Makefiles with an explicit executable name for gcc, this won't work.) Otherwise, put something like this into your .profile:

export CC=/opt/gcc-4.6.3/<path to cc>  CXX=/opt/gcc-4.6.3/<path to g++>

You might be able to get away with just adding /opt/gcc-4.6.3/bin (if that's where the executables are) to your PATH.

share|improve this answer
add comment
up vote 0 down vote accepted

First of all thanks to rici for answering, his method works but I just found one that better suits me.

first I save the old gcc under a different name in case things go awry:

mv /usr/bin/gcc /usr/bin/gcc_old
mv /usr/bin/g++ /usr/bin/g++_old

then I link my new build to gcc and copy some important stuff:

ln -s -f /opt/gcc-4.6.3/bin/gcc /usr/bin/gcc
ln -s -f /opt/gcc-4.6.3/bin/g++ /usr/bin/g++

cp /opt/gcc-4.6.3/lib64/libstdc++.so.6.0.16 /usr/lib64/.
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s -f /usr/lib64/libstdc++.so.6.0.16 /usr/lib64/libstdc++.so.6

My thanks to Jacky Wei from the hiphop facebook git-team for the help. Hope this helps other people aswell.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.