How to install GNU GCC 8 on CentOS 7

Author:

It has been long after releasing the GNU GCC 8.x, but at last, there is a trusted repository, which has offered us packages for GNU GCC 8.x, which won’t break your system! Many of us prefer CentOS 7 because it offers free enterprise-class operating system and as mentioned in our article before – How to install new gcc and development tools under CentOS 7 there are a couple of approved external repositories for CentOS, which you can trust https://wiki.centos.org/AdditionalResources/Repositories. In one of them Software Collection – https://www.softwarecollections.org/en/scls/ several months ago the GNU GCC 8.x packages were added!
At present, the GNU GCC version is gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3).
Here are the steps how you can install GNU GCC 8 and how you can use it:

STEP 1) Update your system and install the repository in your system

The commands:

1
2
yum update -y
yum -y install centos-release-scl


The output in our server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[root@my-centos7 ~]# yum update -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.coreix.net
 * extras: mirror.netweaver.uk
 * updates: mirror.netweaver.uk
No packages marked for update
[root@my-centos7 ~]# yum -y install centos-release-scl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.coreix.net
 * extras: mirror.netweaver.uk
 * updates: mirror.netweaver.uk
Resolving Dependencies
--> Running transaction check
---> Package centos-release-scl.noarch 0:2-3.el7.centos will be installed
--> Processing Dependency: centos-release-scl-rh for package: centos-release-scl-2-3.el7.centos.noarch
--> Running transaction check
---> Package centos-release-scl-rh.noarch 0:2-3.el7.centos will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
============================================================================================================================================================================
 Package                                           Arch                               Version                                      Repository                          Size
============================================================================================================================================================================
Installing:
 centos-release-scl                                noarch                             2-3.el7.centos                               extras                              12 k
Installing for dependencies:
 centos-release-scl-rh                             noarch                             2-3.el7.centos                               extras                              12 k
 
Transaction Summary
============================================================================================================================================================================
Install  1 Package (+1 Dependent package)
 
Total download size: 24 k
Installed size: 39 k
Downloading packages:
(1/2): centos-release-scl-rh-2-3.el7.centos.noarch.rpm                                                                                               |  12 kB  00:00:00    
(2/2): centos-release-scl-2-3.el7.centos.noarch.rpm                                                                                                  |  12 kB  00:00:00    
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                       156 kB/s |  24 kB  00:00:00    
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : centos-release-scl-rh-2-3.el7.centos.noarch                                                                                                              1/2
  Installing : centos-release-scl-2-3.el7.centos.noarch                                                                                                                 2/2
  Verifying  : centos-release-scl-2-3.el7.centos.noarch                                                                                                                 1/2
  Verifying  : centos-release-scl-rh-2-3.el7.centos.noarch                                                                                                              2/2
 
Installed:
  centos-release-scl.noarch 0:2-3.el7.centos                                                                                                                               
 
Dependency Installed:
  centos-release-scl-rh.noarch 0:2-3.el7.centos                                                                                                                            
 
Complete!

STEP 2) Install the development tools and GNU GCC 8, which is part of the “devtools” package

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
[root@my-centos7 ~]# yum install devtoolset-8
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.coreix.net
 * centos-sclo-rh: mirror.netweaver.uk
 * centos-sclo-sclo: mirror.netweaver.uk
 * extras: mirror.netweaver.uk
 * updates: mirror.netweaver.uk
Resolving Dependencies
--> Running transaction check
---> Package devtoolset-8.x86_64 0:8.1-1.el7 will be installed
--> Processing Dependency: devtoolset-8-toolchain for package: devtoolset-8-8.1-1.el7.x86_64
--> Processing Dependency: devtoolset-8-runtime for package: devtoolset-8-8.1-1.el7.x86_64
--> Processing Dependency: devtoolset-8-perftools for package: devtoolset-8-8.1-1.el7.x86_64
--> Running transaction check
---> Package devtoolset-8-perftools.x86_64 0:8.1-1.el7 will be installed
--> Processing Dependency: devtoolset-8-valgrind for package: devtoolset-8-perftools-8.1-1.el7.x86_64
--> Processing Dependency: devtoolset-8-systemtap for package: devtoolset-8-perftools-8.1-1.el7.x86_64
--> Processing Dependency: devtoolset-8-oprofile for package: devtoolset-8-perftools-8.1-1.el7.x86_64
--> Processing Dependency: devtoolset-8-dyninst for package: devtoolset-8-perftools-8.1-1.el7.x86_64
.....
.....
--> Finished Dependency Resolution
 
Dependencies Resolved
 
============================================================================================================================================================================
 Package                                               Arch                          Version                                    Repository                             Size
============================================================================================================================================================================
Installing:
 devtoolset-8                                          x86_64                        8.1-1.el7                                  centos-sclo-rh                        5.4 k
Installing for dependencies:
 audit-libs-python                                     x86_64                        2.8.4-4.el7                                base                                   76 k
 avahi-libs                                            x86_64                        0.6.31-19.el7                              base                                   61 k
 boost-date-time                                       x86_64                        1.53.0-27.el7                              base                                   52 k
 boost-system                                          x86_64                        1.53.0-27.el7                              base                                   40 k
 boost-thread                                          x86_64                        1.53.0-27.el7                              base                                   57 k
 checkpolicy                                           x86_64                        2.5-8.el7                                  base                                  295 k
 cpp                                                   x86_64                        4.8.5-36.el7_6.2                           updates                               5.9 M
 devtoolset-8-binutils                                 x86_64                        2.30-54.el7                                centos-sclo-rh                        5.5 M
 devtoolset-8-dwz                                      x86_64                        0.12-1.1.el7                               centos-sclo-rh                         98 k
 devtoolset-8-dyninst                                  x86_64                        9.3.2-6.el7                                centos-sclo-rh                        3.6 M
 devtoolset-8-elfutils                                 x86_64                        0.176-1.el7                                centos-sclo-rh                        431 k
 devtoolset-8-elfutils-libelf                          x86_64                        0.176-1.el7                                centos-sclo-rh                        202 k
 devtoolset-8-elfutils-libs                            x86_64                        0.176-1.el7                                centos-sclo-rh                        311 k
 devtoolset-8-gcc                                      x86_64                        8.3.1-3.1.el7                              centos-sclo-rh                         30 M
 devtoolset-8-gcc-c++                                  x86_64                        8.3.1-3.1.el7                              centos-sclo-rh                         12 M
 devtoolset-8-gcc-gfortran                             x86_64                        8.3.1-3.1.el7                              centos-sclo-rh                         12 M
 devtoolset-8-gdb                                      x86_64                        8.2-3.el7                                  centos-sclo-rh                        3.4 M
 devtoolset-8-libquadmath-devel                        x86_64                        8.3.1-3.1.el7                              centos-sclo-rh                        155 k
 devtoolset-8-libstdc++-devel                          x86_64                        8.3.1-3.1.el7                              centos-sclo-rh                        2.7 M
 devtoolset-8-ltrace                                   x86_64                        0.7.91-1.el7                               centos-sclo-rh                        148 k
 devtoolset-8-make                                     x86_64                        1:4.2.1-4.el7                              centos-sclo-rh                        485 k
 devtoolset-8-memstomp                                 x86_64                        0.1.5-5.el7                                centos-sclo-rh                        442 k
 devtoolset-8-oprofile                                 x86_64                        1.3.0-2.el7                                centos-sclo-rh                        1.8 M
 devtoolset-8-perftools                                x86_64                        8.1-1.el7                                  centos-sclo-rh                        2.8 k
 devtoolset-8-runtime                                  x86_64                        8.1-1.el7                                  centos-sclo-rh                         20 k
 devtoolset-8-strace                                   x86_64                        4.24-4.el7                                 centos-sclo-rh                        1.0 M
 devtoolset-8-systemtap                                x86_64                        3.3-2.el7                                  centos-sclo-rh                        144 k
 devtoolset-8-systemtap-client                         x86_64                        3.3-2.el7                                  centos-sclo-rh                        2.8 M
 devtoolset-8-systemtap-devel                          x86_64                        3.3-2.el7                                  centos-sclo-rh                        2.2 M
 devtoolset-8-systemtap-runtime                        x86_64                        3.3-2.el7                                  centos-sclo-rh                        427 k
 devtoolset-8-toolchain                                x86_64                        8.1-1.el7                                  centos-sclo-rh                        3.0 k
 devtoolset-8-valgrind                                 x86_64                        1:3.14.0-16.el7                            centos-sclo-rh                         11 M
 gcc                                                   x86_64                        4.8.5-36.el7_6.2                           updates                                16 M
 glibc-devel                                           x86_64                        2.17-260.el7_6.6                           updates                               1.1 M
 glibc-headers                                         x86_64                        2.17-260.el7_6.6                           updates                               684 k
 kernel-debug-devel                                    x86_64                        3.10.0-957.27.2.el7                        updates                                17 M
 kernel-headers                                        x86_64                        3.10.0-957.27.2.el7                        updates                               8.0 M
 libcgroup                                             x86_64                        0.41-20.el7                                base                                   66 k
 libgfortran5                                          x86_64                        8.2.1-1.3.1.el7_5                          updates                               796 k
 libmpc                                                x86_64                        1.0.1-3.el7                                base                                   51 k
 libquadmath                                           x86_64                        4.8.5-36.el7_6.2                           updates                               189 k
 libsemanage-python                                    x86_64                        2.5-14.el7                                 base                                  113 k
 mpfr                                                  x86_64                        3.1.1-4.el7                                base                                  203 k
 perl                                                  x86_64                        4:5.16.3-294.el7_6                         updates                               8.0 M
 perl-Carp                                             noarch                        1.26-244.el7                               base                                   19 k
 perl-Encode                                           x86_64                        2.51-7.el7                                 base                                  1.5 M
 perl-Exporter                                         noarch                        5.68-3.el7                                 base                                   28 k
 perl-File-Path                                        noarch                        2.09-2.el7                                 base                                   26 k
 perl-File-Temp                                        noarch                        0.23.01-3.el7                              base                                   56 k
 perl-Filter                                           x86_64                        1.49-3.el7                                 base                                   76 k
 perl-Getopt-Long                                      noarch                        2.40-3.el7                                 base                                   56 k
 perl-HTTP-Tiny                                        noarch                        0.033-3.el7                                base                                   38 k
 perl-PathTools                                        x86_64                        3.40-5.el7                                 base                                   82 k
 perl-Pod-Escapes                                      noarch                        1:1.04-294.el7_6                           updates                                51 k
 perl-Pod-Perldoc                                      noarch                        3.20-4.el7                                 base                                   87 k
 perl-Pod-Simple                                       noarch                        1:3.28-4.el7                               base                                  216 k
 perl-Pod-Usage                                        noarch                        1.63-3.el7                                 base                                   27 k
 perl-Scalar-List-Utils                                x86_64                        1.27-248.el7                               base                                   36 k
 perl-Socket                                           x86_64                        2.010-4.el7                                base                                   49 k
 perl-Storable                                         x86_64                        2.45-3.el7                                 base                                   77 k
 perl-Text-ParseWords                                  noarch                        3.29-4.el7                                 base                                   14 k
 perl-Time-HiRes                                       x86_64                        4:1.9725-3.el7                             base                                   45 k
 perl-Time-Local                                       noarch                        1.2300-2.el7                               base                                   24 k
 perl-constant                                         noarch                        1.27-2.el7                                 base                                   19 k
 perl-libs                                             x86_64                        4:5.16.3-294.el7_6                         updates                               688 k
 perl-macros                                           x86_64                        4:5.16.3-294.el7_6                         updates                                44 k
 perl-parent                                           noarch                        1:0.225-244.el7                            base                                   12 k
 perl-podlators                                        noarch                        2.5.1-3.el7                                base                                  112 k
 perl-threads                                          x86_64                        1.87-4.el7                                 base                                   49 k
 perl-threads-shared                                   x86_64                        1.43-6.el7                                 base                                   39 k
 policycoreutils-python                                x86_64                        2.5-29.el7_6.1                             updates                               456 k
 python-IPy                                            noarch                        0.75-6.el7                                 base                                   32 k
 scl-utils                                             x86_64                        20130529-19.el7                            base                                   24 k
 setools-libs                                          x86_64                        3.3.8-4.el7                                base                                  620 k
 unzip                                                 x86_64                        6.0-19.el7                                 base                                  170 k
 zip                                                   x86_64                        3.0-11.el7                                 base                                  260 k
 
Transaction Summary
============================================================================================================================================================================
Install  1 Package (+76 Dependent packages)
 
Total download size: 155 M
Installed size: 411 M
Is this ok [y/d/N]: y
Downloading packages:
(1/77): audit-libs-python-2.8.4-4.el7.x86_64.rpm
.....
.....
Installed:
  devtoolset-8.x86_64 0:8.1-1.el7                                                                                                                                          
 
Dependency Installed:
  audit-libs-python.x86_64 0:2.8.4-4.el7                   avahi-libs.x86_64 0:0.6.31-19.el7                    boost-date-time.x86_64 0:1.53.0-27.el7                   
  boost-system.x86_64 0:1.53.0-27.el7                      boost-thread.x86_64 0:1.53.0-27.el7                  checkpolicy.x86_64 0:2.5-8.el7                           
  cpp.x86_64 0:4.8.5-36.el7_6.2                            devtoolset-8-binutils.x86_64 0:2.30-54.el7           devtoolset-8-dwz.x86_64 0:0.12-1.1.el7                   
  devtoolset-8-dyninst.x86_64 0:9.3.2-6.el7                devtoolset-8-elfutils.x86_64 0:0.176-1.el7           devtoolset-8-elfutils-libelf.x86_64 0:0.176-1.el7        
  devtoolset-8-elfutils-libs.x86_64 0:0.176-1.el7          devtoolset-8-gcc.x86_64 0:8.3.1-3.1.el7              devtoolset-8-gcc-c++.x86_64 0:8.3.1-3.1.el7              
  devtoolset-8-gcc-gfortran.x86_64 0:8.3.1-3.1.el7         devtoolset-8-gdb.x86_64 0:8.2-3.el7                  devtoolset-8-libquadmath-devel.x86_64 0:8.3.1-3.1.el7    
  devtoolset-8-libstdc++-devel.x86_64 0:8.3.1-3.1.el7      devtoolset-8-ltrace.x86_64 0:0.7.91-1.el7            devtoolset-8-make.x86_64 1:4.2.1-4.el7                   
  devtoolset-8-memstomp.x86_64 0:0.1.5-5.el7               devtoolset-8-oprofile.x86_64 0:1.3.0-2.el7           devtoolset-8-perftools.x86_64 0:8.1-1.el7                
  devtoolset-8-runtime.x86_64 0:8.1-1.el7                  devtoolset-8-strace.x86_64 0:4.24-4.el7              devtoolset-8-systemtap.x86_64 0:3.3-2.el7                
  devtoolset-8-systemtap-client.x86_64 0:3.3-2.el7         devtoolset-8-systemtap-devel.x86_64 0:3.3-2.el7      devtoolset-8-systemtap-runtime.x86_64 0:3.3-2.el7        
  devtoolset-8-toolchain.x86_64 0:8.1-1.el7                devtoolset-8-valgrind.x86_64 1:3.14.0-16.el7         gcc.x86_64 0:4.8.5-36.el7_6.2                            
  glibc-devel.x86_64 0:2.17-260.el7_6.6                    glibc-headers.x86_64 0:2.17-260.el7_6.6              kernel-debug-devel.x86_64 0:3.10.0-957.27.2.el7          
  kernel-headers.x86_64 0:3.10.0-957.27.2.el7              libcgroup.x86_64 0:0.41-20.el7                       libgfortran5.x86_64 0:8.2.1-1.3.1.el7_5                  
  libmpc.x86_64 0:1.0.1-3.el7                              libquadmath.x86_64 0:4.8.5-36.el7_6.2                libsemanage-python.x86_64 0:2.5-14.el7                   
  mpfr.x86_64 0:3.1.1-4.el7                                perl.x86_64 4:5.16.3-294.el7_6                       perl-Carp.noarch 0:1.26-244.el7                          
  perl-Encode.x86_64 0:2.51-7.el7                          perl-Exporter.noarch 0:5.68-3.el7                    perl-File-Path.noarch 0:2.09-2.el7                       
  perl-File-Temp.noarch 0:0.23.01-3.el7                    perl-Filter.x86_64 0:1.49-3.el7                      perl-Getopt-Long.noarch 0:2.40-3.el7                     
  perl-HTTP-Tiny.noarch 0:0.033-3.el7                      perl-PathTools.x86_64 0:3.40-5.el7                   perl-Pod-Escapes.noarch 1:1.04-294.el7_6                 
  perl-Pod-Perldoc.noarch 0:3.20-4.el7                     perl-Pod-Simple.noarch 1:3.28-4.el7                  perl-Pod-Usage.noarch 0:1.63-3.el7                       
  perl-Scalar-List-Utils.x86_64 0:1.27-248.el7             perl-Socket.x86_64 0:2.010-4.el7                     perl-Storable.x86_64 0:2.45-3.el7                        
  perl-Text-ParseWords.noarch 0:3.29-4.el7                 perl-Time-HiRes.x86_64 4:1.9725-3.el7                perl-Time-Local.noarch 0:1.2300-2.el7                    
  perl-constant.noarch 0:1.27-2.el7                        perl-libs.x86_64 4:5.16.3-294.el7_6                  perl-macros.x86_64 4:5.16.3-294.el7_6                    
  perl-parent.noarch 1:0.225-244.el7                       perl-podlators.noarch 0:2.5.1-3.el7                  perl-threads.x86_64 0:1.87-4.el7                         
  perl-threads-shared.x86_64 0:1.43-6.el7                  policycoreutils-python.x86_64 0:2.5-29.el7_6.1       python-IPy.noarch 0:0.75-6.el7                           
  scl-utils.x86_64 0:20130529-19.el7                       setools-libs.x86_64 0:3.3.8-4.el7                    unzip.x86_64 0:6.0-19.el7                                
  zip.x86_64 0:3.0-11.el7                                
 
Complete!

STEP 3) Use the installed tools.

Because using such a package with multiple complex packages you must configure multiple environments and links to the versions you installed replacing the ones from your base system, but the package comes with a handy tool, which executing it will configure everything and you are ready to go!

1
scl enable devtoolset-8 bash

Whenever you want to use the new GCC you must execute it or you will end up with the default one.

1
2
3
4
5
6
[root@my-centos7 ~]# scl enable devtoolset-8 bash
[root@my-centos7 ~]# 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.

Using Software Collection you could install multiple GNU GCC version 6, 7 (we have article on the subject – How to install new gcc and development tools under CentOS 7) and now 8.

2 thoughts on “How to install GNU GCC 8 on CentOS 7”

Leave a Reply

Your email address will not be published. Required fields are marked *