Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing gcc 4.8 and Linuxbrew on CentOS 6

Installing gcc 4.8 and Linuxbrew on CentOS 6

The GCC distributed with CentOS 6 is 4.4.7, which is pretty outdated. I'd like to use gcc 4.8+. Also, when trying to install Linuxbrew you run into a dependency loop where Homebrew's gcc depends on zlib, which depends on gcc. Here's how I solved the problem.

Note: Requires sudo privileges.

Resources:

Upgrading gcc

First, verify which version of CentOS you're using:

$ cat /etc/centos-release
CentOS release 6.7 (Final)

Import CERN's GPG key:

sudo rpm --import http://ftp.scientificlinux.org/linux/scientific/5x/x86_64/RPM-GPG-KEYs/RPM-GPG-KEY-cern

Save repository information as /etc/yum.repos.d/slc6-devtoolset.repo on your system:

wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo

Install:

sudo yum install devtoolset-2

Enable the environment:

scl enable devtoolset-2 bash

Test the environment:

$ gcc --version
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
...

$ g++ --version
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
...

$ gfortran --version
GNU Fortran (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
...

Optional: Permanently enable scl toolchain by putting this in your .bashrc (warning: don't try to use the scl enable devtoolset-2 bash command from before in your .bashrc. This spawns a new bash shell, and if that's in your .bashrc, it creates a new shell, which loads your .bashrc, which creates a new shell, etc.)

source /opt/rh/devtoolset-2/enable

Installing Linuxbrew

Enable the SCL environment:

scl enable devtoolset-2 bash

Create symlinks to your new gcc/g++/gfortran:

ln -s $(which gcc) `brew --prefix`/bin/gcc-$(gcc -dumpversion |cut -d. -f1,2)
ln -s $(which g++) `brew --prefix`/bin/g++-$(g++ -dumpversion |cut -d. -f1,2)
ln -s $(which gfortran) `brew --prefix`/bin/gfortran-$(gfortran -dumpversion |cut -d. -f1,2)

Install Linuxbrew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"

Add these to your .bashrc, and source it:

export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"

Test your installation:

brew install hello
brew test hello
brew remove hello
@kompa3

This comment has been minimized.

Copy link

kompa3 commented Dec 16, 2015

I managed to install g++ 4.8.2 on Redhat 6.7 with the following commands:

sudo wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
sudo rpm --import http://ftp.scientificlinux.org/linux/scientific/5x/x86_64/RPM-GPG-KEYs/RPM-GPG-KEY-cern
sudo yum install devtoolset-2-gcc-c++-4.8.2-15.1.el6
echo "source /opt/rh/devtoolset-2/enable" >> ~/.bashrc
@tomck

This comment has been minimized.

Copy link

tomck commented May 6, 2016

There's a slightly more official way, now that devtoolset-2 is deprecated.

https://www.softwarecollections.org/en/scls/rhscl/devtoolset-3/

CERN's page covers this: http://linux.web.cern.ch/linux/devtoolset/

@stephenturner

This comment has been minimized.

Copy link
Owner Author

stephenturner commented Jun 8, 2016

Here's how I upgraded gcc on my latest 6.7 build.

$ cat /etc/centos-release
CentOS release 6.7 (Final)

$ sudo yum install centos-release-scl
$ sudo yum install devtoolset-3-toolchain
$ scl enable devtoolset-3 bash

$ gcc --version
gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
...

$ g++ --version
g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
...

$ gfortran --version
GNU Fortran (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
...
@bhavyaw

This comment has been minimized.

Copy link

bhavyaw commented Jun 30, 2016

@stephenturner.

Thanks. It worked perfectly!

@belm

This comment has been minimized.

Copy link

belm commented Jul 1, 2016

good work

@belm

This comment has been minimized.

Copy link

belm commented Jul 1, 2016

sudo wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
sudo rpm --import http://ftp.scientificlinux.org/linux/scientific/5x/x86_64/RPM-GPG-KEYs/RPM-GPG-KEY-cern
sudo yum install devtoolset-2-gcc-c++-4.8.2-15.1.el6
echo "source /opt/rh/devtoolset-2/enable" >> ~/.bashrc
source ~/.bashrc
gcc -v

@timbowhite

This comment has been minimized.

Copy link

timbowhite commented Sep 15, 2016

@stephenturner thanks you da real MVP :)

@GiveMeAllYourCats

This comment has been minimized.

Copy link

GiveMeAllYourCats commented Nov 9, 2016

Why can't I 1+ this man!?!
Thank you @stephenturner !

@Andy5168

This comment has been minimized.

Copy link

Andy5168 commented Dec 28, 2016

Who can tell me how to resolve C/CXX compiler identification is unknown issue? (RHEL 6 install gcc-4.8.2)
I follow below to install but looks like the compiler is not properly installed
sudo wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
sudo rpm --import http://ftp.scientificlinux.org/linux/scientific/5x/x86_64/RPM-GPG-KEYs/RPM-GPG-KEY-cern
sudo yum install devtoolset-2-gcc-c++-4.8.2-15.1.el6
echo "source /opt/rh/devtoolset-2/enable" >> ~/.bashrc
Building for SHARP
-- # The C compiler identification is unknown
-- # The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
I got GCC version 4.8.2 that is fine

cc -v

Using built-in specs.
COLLECT_GCC=cc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/opt/rh/devtoolset-2/root/usr --mandir=/opt/rh/devtoolset-2/root/usr/share/man --infodir=/opt/rh/devtoolset-2/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,fortran,lto --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/cloog-install --with-mpc=/builddir/build/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC)

Thanks!

@fahadmehar

This comment has been minimized.

Copy link

fahadmehar commented Jan 21, 2017

I have this issue on my Centos 7

checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in /home/Statistics/eggdrop-1.8': configure: error: no acceptable C compiler found in $PATH See config.log' for more details

@s270987763

This comment has been minimized.

Copy link

s270987763 commented Mar 15, 2017

nice work

@suyuTech

This comment has been minimized.

Copy link

suyuTech commented May 6, 2017

@stephenturner Thanks a lot! I upgraded gcc successfully follow your tips, but gcc go back to original version again when I log in the server using ssh again.

@agcarlon

This comment has been minimized.

Copy link

agcarlon commented May 29, 2017

I did what stephenturner said:

$ cat /etc/centos-release
CentOS release 6.9 (Final)

$ sudo yum install centos-release-scl
$ sudo yum install devtoolset-3-toolchain
$ scl enable devtoolset-3 bash

$ gcc --version
gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)

but when I try to cmake my package it says

bash-4.1$ cmake ..
CMake Error at CMakeLists.txt:28 (message):
GCC version must be at least 4.6 (for sufficient C++11 support. You have
version 4.4.7

-- Configuring incomplete, errors occurred!

I tried running

scl enable devtoolset-3 'cmake ..'

same error.
What should I do?

@tegansnyder

This comment has been minimized.

Copy link

tegansnyder commented Jun 20, 2017

Here is how I got mine working on RHEL 6.8

cd /etc/pki/rpm-gpg
wget http://linuxsoft.cern.ch/cern/scl/RPM-GPG-KEY-cern

cd /etc/yum.repos.d
wget http://linuxsoft.cern.ch/cern/scl/slc6-scl.repo

yum install -y devtoolset-3-gcc-c++

# switch to new gcc
source /opt/rh/devtoolset-3/enable
gcc -v
@jinleileiking

This comment has been minimized.

Copy link

jinleileiking commented Sep 1, 2017

bravo!

@jonefeewang

This comment has been minimized.

Copy link

jonefeewang commented Sep 14, 2017

Thanks, this is also working on CentOS 6.4
but with a small issue. For Chinese users, the repo uses "mirrorlist.centos.org"/.. as the base URL. it will be very slow, change it "mirrors.163.com" will be much faster.

@agcarlon
apparently, your old version GCC is still in the $PATH, change it. clean your package's work space and retry.

@jbenjam

This comment has been minimized.

Copy link

jbenjam commented Sep 20, 2017

I have a related question: I'm trying to build a testing environment for multiple versions of gfortran, and would like to locally install different versions of gcc and be able to switch between them.

I do not have root or sudo access, and yum localinstall is not allowed. Brew is not installed.

I'd like to test versions 4.4 - 8.x, and would be testing the latest stable release version in each major revision.

Running CentOS release 6.9 (Final) [2.6.32-431.20.3.el6.centos.plus.x86_64]

The current version of gcc is

gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18)

What's an effective way of doing this?

@remoharsono

This comment has been minimized.

Copy link

remoharsono commented Nov 14, 2017

@stephenturner thank you, it's work on my centos 6.9

@tkhk11

This comment has been minimized.

Copy link

tkhk11 commented Dec 3, 2017

@tegansnyder I followed your instruction. When executing yum install -y devtoolset-3-gcc-c++, I got the following error:

Loaded plugins: refresh-packagekit, security, ulninfo
Setting up Install Process
slc6-scl | 2.6 kB 00:00
slc6-scl/primary_db | 1.0 MB 00:02
http://people.centos.org/tru/devtools-2/6Server/x86_64/RPMS/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: testing-devtools-2-centos-6Server. Please verify its path and try again

My centos is Red Hat Enterprise Linux Server release 6.9 (Santiago). my gcc is gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18).
I am a novice to Linux.

Could you help me to solve this error?

@leizongmin

This comment has been minimized.

Copy link

leizongmin commented Feb 23, 2018

Cannot import the CERN's GPG key. I use this command to instead of it:

rpm --import http://linuxsoft.cern.ch/cern/slc6X/x86_64/RPM-GPG-KEY-cern

@wangxianhe

This comment has been minimized.

Copy link

wangxianhe commented Aug 20, 2018

@stephenturner
Great!
thank you so much!

@daehyeon-han

This comment has been minimized.

Copy link

daehyeon-han commented Jan 16, 2019

Thank you! I solve the problem.

@ichandan16

This comment has been minimized.

Copy link

ichandan16 commented Nov 6, 2019

yum install -y devtoolset-3-gcc-c++

Awesome! Thank you!!!

@speccius

This comment has been minimized.

Copy link

speccius commented Feb 23, 2020

the rpm --import command failed with Error 404, where is the new file location?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.