| Below bash script is for installing gcc 4.9.4 in CentOS 7 #!/bin/bash
# Install Development Tools
sudo yum groupinstall "Development Tools"
# Install dependencies
sudo yum install gcc gcc-c++ gmp-devel mpfr-devel libmpc-devel
# Download and extract GCC source code
cd $HOME
wget http://ftp.gnu.org/gnu/gcc/gcc-4.9.4/gcc-4.9.4.tar.gz
if [ ! -f gcc-4.9.4.tar.gz ]; then
echo "Error: gcc-4.9.4.tar.gz not found"
exit 1
fi
if [ -d gcc-4.9.4 ]; then
rm -rf gcc-4.9.4
fi
tar -xvzf gcc-4.9.4.tar.gz
cd gcc-4.9.4
# Download prerequisites
./contrib/download_prerequisites
# Configure and build GCC
mkdir ../gcc-build
cd ../gcc-build
# Configure GCC with specific options
../gcc-4.9.4/configure --enable-languages=c,c++ --disable-multilib --prefix=/usr/local/gcc-4.9.4
# Build GCC
make -j$(nproc)
sudo make install
# Update environment variables
echo 'export PATH=/usr/local/gcc-4.9.4/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/gcc-4.9.4/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
# Verify installation
gcc --version
g++ --version
# Clean up
rm -rf gcc-4.9.4 gcc-build gcc-4.9.4.tar.gz
For your information, you should have sudo permission to install the above. |