Centos – What’s the preferred way of upgrading CentOS 5.5 to use the latest stable release of gcc

centosgccredhatrhel5

Seems that gcc on CentOS 5.5 is a few versions behind the latest, which has some optimizations that I would seriously welcome. What is the best practice for installing and upgrading gcc?

Best Answer

The best practice for upgrading gcc away from the stock CentOS version is: don't.

It's a lot of hassle, there's a lot of dependencies, and you're likely to break something. And it's very unlikely that you'll get any kind of noticeable benefit from those optimizations.

Let me reiterate: it's best to stick with the stock GCC on CentOS/RH.

However, if you're really determined to, I'd install it into /opt, specifically something like /opt/gcc-4.5.1/. You'll have /opt/gcc-4.5.1/bin, /opt/gcc-4.5.1/lib, etc.. Symlink /opt/gcc to /opt/gcc-4.5.1 and put /opt/gcc/bin in your path, etc. That way you'll still be able to pick which gcc you're going to run so that normal tools that really need the correct CentOS gcc release will work right and you can run your special GCC as needed. And that way when you update to gcc-4.6.7 you install it into /opt/gcc-4.6.7, change the /opt/gcc symlink and remove the /opt/gcc-4.5.1 directory and be done with the update.