How to update GCC from 4.8 to 8.2 on RHEL7
Asked Answered
W

2

6

I am looking to update my GCC to the newest version (8.2 as of today) but when I attempt to use yum update gcc it doesn't have any new packages to update. I am also not having any help looking at the GCC's website. Any help would be greatly appreciated!

Wulfenite answered 11/1, 2019 at 16:38 Comment(0)
B
8

Red Hat Enterprise Linux, being an "enterprise" operating system, is designed to be stable and similar for a long time. That means you do not get the "latest and greatest" by default, but a known-good implementation that remains the default on that particular RHEL version for the long term. Generally you only get substantial software upgrades by upgrading RHEL. Unfortunately, there is no RHEL 8 yet.

devtoolset allows you to switch to newer, out-of-band versions of development software like GCC, in a way that doesn't "contaminate" the whole OS installation. I used it, with great success, to get GCC 4.8 (and its C++11 support) on CentOS 6, where the official GCC is 4.4.

devtoolset-8 has GCC 8.2.1.

Or you could choose to use a distribution more suited for home users, such as Fedora.

Or you could download the GCC source and build it yourself (but ew!).

Baseborn answered 11/1, 2019 at 16:44 Comment(0)
S
4

One can surely build the gcc on CentOS oneself(though ew!).

Generally follow the below steps:

sudo yum -y update
sudo yum -y install bzip2 wget gcc gcc-c++ gmp-devel mpfr-devel libmpc-devel make
gcc --version
wget http://mirrors-usa.go-parts.com/gcc/releases/gcc-8.2.0/gcc-8.2.0.tar.gz
tar zxf gcc-8.2.0.tar.gz
mkdir gcc-8.2.0-build
cd gcc-8.2.0-build
../gcc-8.2.0/configure --enable-languages=c,c++ --disable-multilib
make -j 2
sudo make install
gcc --version

At this point, many can not see 8.2, i.e.

gcc version 4.8.5 (GCC)

Just overwrite the old gcc with which just built, i.e.

# which gcc
/usr/local/bin/gcc
# cp gcc/xgcc /usr/local/bin/gcc
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/aarch64-unknown-linux-gnu/7.2.0/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: ../gcc-7.2.0/configure --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 7.2.0 (GCC)

In order to avoid library error, one may need update libstdc as well,

cp ./aarch64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6 /usr/local/lib64/libstdc++.so.6
cp ./stage1-aarch64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6 /usr/lib64/libstdc++.so.6

One may also update libc.so as well, i.e. 2.18

curl -O http://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz
tar zxf glibc-2.18.tar.gz
cd glibc-2.18/
mkdir build
cd build/
../configure --prefix=/usr
make -j2
make install
ln -sf /usr/glibc-2.18/glibc-2.18.so /lib64/libc.so.6

Finally, type /lib64/libc.so.6 to confirm

Mostly, ln would fail, since old relations, and LD is suggested, i.e.

LD_LIBRARY_PATH=/usr/glibc-2.18/lib
export LD_LIBRARY_PATH
Santana answered 23/10, 2019 at 7:14 Comment(2)
Overwriting the system's default gcc is not a good idea.Blench
Do NOT get gcc from a random mirror!Ray

© 2022 - 2024 — McMap. All rights reserved.