install latest gcc on rhel 6 x86_64

76,888

Solution 1

The easiest method by far is to make use of a binary build that's provided through a YUM repository. One such option would be to use the hop5.in repository. Specifically this page: gcc - Various compilers (C, C++, Objective-C, Java, ...). They're providing 4.8.2 which should work with CentOS 6.3 or 6.4. You might want to do an update prior:

$ sudo yum update

The other option would be to make use of the Developer Toolset, specifically the bundled version provided by Scientific Linux.

Following the installation instructions you'll basically do the following 2 steps:

add repositories
$ sudo wget -O /etc/yum.repos.d/slc6-devtoolset.repo \
    http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
$ wget -O /etc/yum.repos.d/slc5-devtoolset.repo \
    http://linuxsoft.cern.ch/cern/devtoolset/slc5-devtoolset.repo
install devtoolset
$ sudo yum install devtoolset-2

Update #1

The hop5.in YUM repository appears to have been removed, so the only recourse is to make use of the devtoolset method highlighted above.

Additional examples for installing via devtoolset are highlighted in this GitHub Gist: Installing gcc 4.8 and Linuxbrew on CentOS 6.

Solution 2

Red Hat Software Collections comes with GCC 4.9 you may look at enabling that channel.

Solution 3

I've built newer gcc versions for rhel6 for several versions now (since 4.7.x to 5.3.1).

The process is fairly easy thanks to Redhat's Jakub Jelinek fedora gcc builds found on koji

Simply grab the latest src rpm for whichever version you require (e.g. 5.3.1).

Basically you would start by determining the build requirements by issuing rpm -qpR src.rpm looking for any version requirements:

rpm -qpR gcc-5.3.1-4.fc23.src.rpm | grep -E '= [[:digit:]]'
binutils >= 2.24
doxygen >= 1.7.1
elfutils-devel >= 0.147
elfutils-libelf-devel >= 0.147
gcc-gnat >= 3.1
glibc-devel >= 2.4.90-13
gmp-devel >= 4.1.2-8
isl = 0.14
isl-devel = 0.14
libgnat >= 3.1
libmpc-devel >= 0.8.1
mpfr-devel >= 2.2.1
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
systemtap-sdt-devel >= 1.3

Now comes the tedious part - any package which has a version higher than provided by yum fro your distro needs to be downloaded from koji, and recursively repeat the process until all dependency requirements are met.

I cheat, btw.
I usually repackage the rpm to contain a correct build tree using the gnu facility to use correctly placed and named requirements, so gmp/mpc/mpfr/isl (cloog is no longer required) are downloaded and untard into the correct path, and the new (bloated) tar is rebuilt into a new src rpm (with minor changes to spec file) with no dependency on their packaged (rpm) versions. Since I know of no one using ADA, I simply remove the portions pertaining to gnat from the specfile, further simplifying the build process, leaving me with just binutils to worry about.
Gcc can actually build with older binutils, so if you're in a hurry, further edit the specfile to require the binutils version already present on your system. This will result in a slightly crippled gcc, but mostly it will perform well enough.
This works quite well mostly.

UPDATE 1

The simplest method for opening a src rpm is probably yum install the rpm and access everything under ~/rpmbuild, but I prefer

mkdir gcc-5.3.1-4.fc23
cd gcc-5.3.1-4.fc23
rpm2cpio ../gcc-5.3.1-4.fc23.src.rpm | cpio -id
tar xf gcc-5.3.1-20160212.tar.bz2
cd gcc-5.3.1-20160212
contrib/download_prerequisites
cd ..
tar caf gcc-5.3.1-20160212.tar.bz2 gcc-5.3.1-20160212
rm -rf gcc-5.3.1-20160212
# remove gnat
sed -i '/%global build_ada 1/ s/1/0/' gcc.spec
sed -i '/%if !%{build_ada}/,/%endif/ s/^/#/' gcc.spec
# remove gmp/mpfr/mpc dependencies
sed -i '/BuildRequires: gmp-devel >= 4.1.2-8, mpfr-devel >= 2.2.1, libmpc-devel >= 0.8.1/ s/.*//' gcc.spec
# remove isl dependency
sed -i '/BuildRequires: isl = %{isl_version}/,/Requires: isl-devel = %{isl_version}/ s/^/#/' gcc.spec
# Either build binutils as I do, or lower requirements
sed -i '/Requires: binutils/ s/2.24/2.20/' gcc.spec
# Make sure you don't break on gcc-java
sed -i '/gcc-java/ s/^/#/' gcc.spec

You also have the choice to set prefix so this rpm will install side-by-side without breaking distro rpm (but requires changing name, and some modifications to internal package names). I usually add an environment-module so I can load and unload this gcc as required (similar to how collections work) as part of the rpm (so I add a new dependency).

Finally create the rpmbuild tree and place the files where hey should go and build:

yum install rpmdevtools rpm-build
rpmdev-setuptree
cp * ~/rpmbuild/SOURCES/
mv ~/rpmbuild/{SOURCES,SPECS}/gcc.spec
rpmbuild -ba ~/rpmbuild/SPECS/gcc.spec

UPDATE 2

Normally one should not use a "server" os for development - that's why you have fedora which already comes with latest gcc. I have some particular requirements, but you should really consider using the right tool for the task - rhel/centos to run production apps, fedora to develop those apps etc.

Share:
76,888

Related videos on Youtube

rivu
Author by

rivu

Updated on September 18, 2022

Comments

  • rivu
    rivu over 1 year

    I have an RHEL 6 server with gcc version 4.4.7. I wanted to update the gcc version (I think the current one is 4.8). Yum update doesn't work. Also, SO answers for a similar question on CentOS does not work. I followed the methods in the accepted answer, the output is "Error getting repository data for testing-1.1-devtools-6, repository not found". Also I am not sure whether I should follow the methods for CentOs.

    Has anyone updated gcc in RHEL 6 x86_64 server?

    • Admin
      Admin about 10 years
      Did you try to install it from this repo? hop5.in/yum/el6/repoview/gcc.html. These are binary builds of 4.8.2. You'll likely need to be at 6.4 CentOS to install them, which might be your issue.
    • Admin
      Admin about 10 years
      Is installing from source an option?
    • Admin
      Admin about 10 years
      yes i can install from source if needed.
    • Admin
      Admin about 8 years
      good question. Who's the downvoter? :(
    • Admin
      Admin about 8 years
      Any particular reason why you want to break your system? Have you checked if whatever you expect to win hasn't been backported to RHEL's compiler?
  • rivu
    rivu about 10 years
    I tried to install the rpm downloaded from the first link, says "error: Failed dependencies: cpp = 4.8.2-8.el6 is needed by gcc-4.8.2-8.el6.x86_64 ...". For the developer toolset, it says "people.centos.org/tru/devtools-1.1/6Server/x86_64/RPMS/repo‌​data/…: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found". I think the problem is it is 6Server instead of 6 in the link. I don't know how to fix that.
  • Otheus
    Otheus about 8 years
    hop.in no longer has what I think you think it has.
  • Otheus
    Otheus about 8 years
    Additional step possibly needed: Downloading and importing cern key from http://ftp.scientificlinux.org/linux/scientific/5x/x86_64/RP‌​M-GPG-KEYs/RPM-GPG-K‌​EY-cern. I love that the site doesn't have https. Way to go scilinux. After you download it (tmp directory or whever), import it with rpm --import RPM-GPG-KEY-cern and then do yum install.
  • slm
    slm about 8 years
    @Otheus - thanks, I hate when repos bite the dust like this, wrecks a bunch of content on the interwebs 8-).
  • Dani_l
    Dani_l about 8 years
    It's polite when down-voting to give a reason.
  • dhag
    dhag over 6 years
    Security is a big deal, yet you install from a non-HTTPS location :)?
  • Areeb Soo Yasir
    Areeb Soo Yasir over 5 years
    At the time there was no SSL enabled on the mirrors.kernel.org site but I think if we can't trust kernel.org we have bigger problems :).
  • miken32
    miken32 about 5 years
    Worth mentioning that devtoolset-2-gcc (for me at least) installed a dozen packages and a 35 MB download, versus 280 packages and 575 MB download for yum install devtoolset-2.