Skip to content

Instantly share code, notes, and snippets.

@stephenturner
Last active October 21, 2024 15:21
Show Gist options
  • Save stephenturner/e3bc5cfacc2dc67eca8b to your computer and use it in GitHub Desktop.
Save stephenturner/e3bc5cfacc2dc67eca8b to your computer and use it in GitHub Desktop.
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
@remoharsono
Copy link

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

@tkhk11
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
Copy link

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
Copy link

@stephenturner
Great!
thank you so much!

@daehyeon-han
Copy link

Thank you! I solve the problem.

@ichandan16
Copy link

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

Awesome! Thank you!!!

@thevbw
Copy link

thevbw commented Feb 23, 2020

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

@xiaotianhu
Copy link

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

works! really great help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment