20

I'm used to install packages on Debian/Ubuntu distributions, but now I need to install gcc and g++ version 8.*. There is only version 4.* in CentOS repositories. What's the correct way to install them manually?

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
Eenoku
  • 2,741
  • 4
  • 32
  • 64

3 Answers3

48

CentOS 8 already comes with GCC 8.

On CentOS 7, you can install GCC 8 from Developer Toolset. First you need to enable the Software Collections repository:

yum install centos-release-scl

Then you can install GCC 8 and its C++ compiler:

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

To switch to a shell which defaults gcc and g++ to this GCC version, use:

scl enable devtoolset-8 -- bash

You need to wrap all commands under the scl call, so that the process environment changes performed by this command affect all subshells. For example, you could use the scl command to invoke a shell script that performs the required actions.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • 1
    You can find more details for working with software collections in [How to install GCC 8 and LLVM 6 on RHEL](https://developers.redhat.com/blog/2019/03/05/yum-install-gcc-8-clang-6/) including how to permanently enable the collection so that gcc/g++ 8 will always be in your path. – Rob T. Mar 26 '19 at 22:22
  • 5
    # yum install centos-release-scl No match for argument: centos-release-scl I'm using CentOS 8. Where can I get the packages installed here? – Nick Weavers Jan 16 '20 at 12:22
  • It helps on CentOS 7. Just replace the `8` with `10` to install G++/CCC 10. – GoingMyWay Jun 15 '23 at 06:58
  • 1
    Answer didn't work for CentOS7. Attempted `scl enable devtoolset-8 -- bash` and the bash shell still uses the old gcc/g++. HOWEVER `scl enable devtoolset-8 -- gcc --version` does work. – John Rocha Jun 16 '23 at 18:33
17

Permanently adding DTS to your development environment

After installing the devtoolset:

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

You can also use the following command, to make DTS the default:

source scl_source enable devtoolset-8

The benefit of this command is that it can be added to .bashrc, so that you don't have to run the scl command every time you login:

scl enable devtoolset-8 -- bash
George Valkov
  • 1,217
  • 12
  • 10
4

CentOS 8, to install dev tools: sudo dnf groupinstall "Development Tools"

https://linuxhint.com/install_gcc_build_tools_centos8/

Boppity Bop
  • 9,613
  • 13
  • 72
  • 151