如何将CentOS 6.9中的GCC 4.7.2升级至GCC 4.8.5
Hey there! CentOS 6.9’s default package repositories only ship with GCC 4.7.2, so we’ll use the Software Collections (SCL) to install GCC 4.8.5—this method keeps your system’s default GCC intact (critical for avoiding dependency issues with core system tools). Here’s a straightforward step-by-step guide:
Step 1: Add the CentOS Software Collections Repository
First, we need to enable the SCL repo, which isn’t active by default on CentOS 6.9:
sudo yum install -y centos-release-scl
Step 2: Install GCC 4.8.5 via Devtoolset-2
The SCL package for GCC 4.8.5 is bundled under devtoolset-2. Install the required compiler packages:
sudo yum install -y devtoolset-2-gcc devtoolset-2-gcc-c++
Step 3: Activate the GCC 4.8.5 Environment
SCL packages don’t overwrite your system’s default tools—you need to explicitly activate the environment to use them. For a temporary activation (only applies to your current shell session):
scl enable devtoolset-2 bash
Verify the upgrade worked with these commands:
gcc --version g++ --version
You should see output confirming gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44) or similar.
Step 4: Make Activation Permanent (Optional)
If you want GCC 4.8.5 to be available every time you log in, add the activation command to your user’s ~/.bashrc file:
echo 'source /opt/rh/devtoolset-2/enable' >> ~/.bashrc
Apply the change right away:
source ~/.bashrc
Quick Note
Your system’s original GCC 4.7.2 remains untouched and will still be used by system processes. The SCL version only takes precedence when you’ve enabled the devtoolset-2 environment, so you won’t break existing dependencies.
内容的提问来源于stack exchange,提问作者lonecoder

