Install latest gcc, g++ on CentOS7

 To install development tools on CentOS7, generally use the following command.

yum groupinstall "Development Tools"

However, RedHat or CentOS Linux tends to prefer older packages with proven stability over newer ones. Therefore, package versions are often lower than Ubuntu. If you check the version after installing gcc, it is 4.8.5.

[root@localhost ~]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

However, sometimes you need to upgrade your gcc or g++ version to build a package that requires the latest c++(for exasmple c++ 14) syntax. However, it is impossible to upgrade gcc to a higher version with yum update. You will have to build the source code or find another way to install it.


Install The Software Collections ( SCL ) Repository first. The SCL Repository supports installing the latest version of the package that is not supported by the yum Repository.

The description of the SCL can be found at  https://wiki.centos.org/AdditionalResources/Repositories/SCL .

yum install centos-release-scl


Next, install the latest version (8.X) of gcc and g++.

yum install devtoolset-8-gcc devtoolset-8-gcc-c++


The following sets the latest version of gcc.g++ as the compiler.

scl enable devtoolset-8 -- bash

Now let's check the compiler version again.

[root@localhost ~]# gcc --version
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

However, this operation does not work when a new shell is opened. If you want to use gcc 8.3 every time you open a shell, add the above command line to your ~/.bashrc file.

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
source /opt/rh/devtoolset-8/enable




댓글

이 블로그의 인기 게시물

Connecting to SQL Server on Raspberry Pi

Making VoIP Phone Using Raspberry Pi

MQTT - Mosquitto MQTT Broker setup on the Ubuntu 20.04