Detailed Steps to Upgrade GCC Version on Linux 8

Click the blue text above to follow Alen

Detailed Steps to Upgrade GCC Version on Linux 8

1 Demonstration Environment

The environment for this demonstration is:

  • Red Hat Enterprise Linux release 8.10 (Ootpa)

2 Check Current GCC Version

Execute the following command to check the current GCC version:

[root@sourcecode ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-21) (GCC)
[root@sourcecode ~]#

3 Download GCC, Upload and Extract

After uploading, extract the package:

[root@sourcecode u01]# tar zxvf gcc-11.3.0.tar.gz

4 Compile and Configure GCC

Execute the following commands to compile and configure GCC:

[root@sourcecode u01]# cd gcc-11.3.0/
[root@sourcecode gcc-11.3.0]# mkdir build
[root@sourcecode gcc-11.3.0]# cd build/
[root@sourcecode build]# ../configure --prefix=/u01/export/gcc-11.3.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libitm support... yes
checking for libsanitizer support... yes
checking for libvtv support... yes
checking for libhsail-rt support... yes
checking for libphobos support... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... no
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for the correct version of gmp.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
https://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

If the following error occurs, you can install using yum install gcc-c++ configure: error: *** A compiler with support for C++11 language features is required. From the log, it can be seen that the following dependency packages need to be installed configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+ Installation method: yum install gmp gmp-devel mpfr mpfr-devel libmpc libmpc-devel

[root@sourcecode build]# make -j4
[ -f stage_final ] || echo stage3 > stage_final
make[1]: Entering directory '/u01/gcc-11.3.0/build'
make[2]: Entering directory '/u01/gcc-11.3.0/build'
make[2]: Leaving directory '/u01/gcc-11.3.0/build'
make[2]: Entering directory '/u01/gcc-11.3.0/build'
mkdir -p -- build-x86_64-pc-linux-gnu/libiberty
Configuring in build-x86_64-pc-linux-gnu/libiberty
Configuring stage 1 in ./intl
Configuring stage 1 in ./lto-plugin
Configuring stage 1 in ./libiberty
configure: creating cache ./config.cache
....................中间过程省略........................
libtool: link: ranlib .libs/libtsan.a
libtool: link: rm -fr .libs/libtsan.lax
libtool: link: ( cd".libs" && rm -f "libtsan.la" && ln -s "../libtsan.la""libtsan.la" )
make[4]: Leaving directory '/u01/gcc-11.3.0/build/x86_64-pc-linux-gnu/libsanitizer/tsan'
make[4]: Entering directory '/u01/gcc-11.3.0/build/x86_64-pc-linux-gnu/libsanitizer'
true"AR_FLAGS=rc""CC_FOR_BUILD=gcc""CFLAGS=-g -O2""CXXFLAGS=-g -O2 -D_GNU_SOURCE""CFLAGS_FOR_BUILD=-g -O2""CFLAGS_FOR_TARGET=-g -O2""INSTALL=/usr/bin/install -c""INSTALL_DATA=/usr/bin/install -c -m 644""INSTALL_PROGRAM=/usr/bin/install -c""INSTALL_SCRIPT=/usr/bin/install -c""JC1FLAGS=""LDFLAGS=""LIBCFLAGS=-g -O2""LIBCFLAGS_FOR_TARGET=-g -O2""MAKE=make""MAKEINFO=/u01/gcc-11.3.0/missing makeinfo --split-size=5000000 --split-size=5000000   ""PICFLAG=""PICFLAG_FOR_TARGET=""SHELL=/bin/sh""RUNTESTFLAGS=""exec_prefix=/u01/export/gcc-11.3.0""infodir=/u01/export/gcc-11.3.0/share/info""libdir=/u01/export/gcc-11.3.0/lib""prefix=/u01/export/gcc-11.3.0""includedir=/u01/export/gcc-11.3.0/include""AR=ar""AS=/u01/gcc-11.3.0/build/./gcc/as""LD=/u01/gcc-11.3.0/build/./gcc/collect-ld""LIBCFLAGS=-g -O2""NM=/u01/gcc-11.3.0/build/./gcc/nm""PICFLAG=""RANLIB=ranlib""DESTDIR=" DO=all multi-do # make
make[4]: Leaving directory '/u01/gcc-11.3.0/build/x86_64-pc-linux-gnu/libsanitizer'
make[3]: Leaving directory '/u01/gcc-11.3.0/build/x86_64-pc-linux-gnu/libsanitizer'
make[2]: Leaving directory '/u01/gcc-11.3.0/build'
[root@sourcecode build]#
[root@sourcecode build]# make install
make[1]: Entering directory '/u01/gcc-11.3.0/build'
/bin/sh ../mkinstalldirs /u01/export/gcc-11.3.0 /u01/export/gcc-11.3.0
mkdir -p -- /u01/export/gcc-11.3.0 /u01/export/gcc-11.3.0
make[2]: Entering directory '/u01/gcc-11.3.0/build/fixincludes'
rm -rf /u01/export/gcc-11.3.0/libexec/gcc/x86_64-pc-linux-gnu/11.3.0/install-tools
/bin/sh ../../fixincludes/../mkinstalldirs /u01/export/gcc-11.3.0/libexec/gcc/x86_64-pc-linux-gnu/11.3.0/install-tools
mkdir -p -- /u01/export/gcc-11.3.0/libexec/gcc/x86_64-pc-linux-gnu/11.3.0/install-tools
/bin/sh ../../fixincludes/../mkinstalldirs /u01/export/gcc-11.3.0/lib/gcc/x86_64-pc-linux-gnu/11.3.0/install-tools/include
mkdir -p -- /u01/export/gcc-11.3.0/lib/gcc/x86_64-pc-linux-gnu/11.3.0/install-tools/include
/usr/bin/install -c -m 644 ../../fixincludes/README-fixinc 
/u01/export/gcc-11.3.0/lib/gcc/x86_64-pc-linux-gnu/11.3.0/install-tools/include/README
/usr/bin/install -c fixinc.sh /u01/export/gcc-11.3.0/libexec/gcc/x86_64-pc-linux-gnu/11.3.0/install-tools/fixinc.sh
/usr/bin/install -c fixincl /u01/export/gcc-11.3.0/libexec/gcc/x86_64-pc-linux-gnu/11.3.0/install-tools/fixincl
/usr/bin/install -c mkheaders /u01/export/gcc-11.3.0/libexec/gcc/x86_64-pc-linux-gnu/11.3.0/install-tools/mkheaders
make[2]: Leaving directory '/u01/gcc-11.3.0/build/fixincludes'
make[2]: Entering directory '/u01/gcc-11.3.0/build/lto-plugin'
make[3]: Entering directory '/u01/gcc-11.3.0/build/lto-plugin'
....................中间过程省略........................
Libraries have been installed in:
   /u01/export/gcc-11.3.0/lib/../lib64

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[4]: Nothing to be done for 'install-data-am'.
make[4]: Leaving directory '/u01/gcc-11.3.0/build/x86_64-pc-linux-gnu/libatomic'
make[3]: Leaving directory '/u01/gcc-11.3.0/build/x86_64-pc-linux-gnu/libatomic'
make[2]: Leaving directory '/u01/gcc-11.3.0/build'
[root@sourcecode build]#

5 Update GCC Version

After compiling and configuring GCC, you also need to update the GCC version, the specific operation is as follows:

[root@sourcecode build]# mv /usr/bin/gcc /usr/bin/gcc.bak
[root@sourcecode build]# mv /usr/bin/g++ /usr/bin/g++.bak
[root@sourcecode build]# mv /usr/bin/c++ /usr/bin/c++.bak
[root@sourcecode build]#
[root@sourcecode build]# mv /usr/bin/cc /usr/bin/cc.bak
[root@sourcecode build]#
[root@sourcecode build]# ln -s /u01/export/gcc-11.3.0/bin/gcc /usr/bin/gcc
[root@sourcecode build]# ln -s /u01/export/gcc-11.3.0/bin/g++ /usr/bin/g++
[root@sourcecode build]# ln -s /u01/export/gcc-11.3.0/bin/c++ /usr/bin/c++
[root@sourcecode build]#
[root@sourcecode build]# ln -s /u01/export/gcc-11.3.0/bin/gcc /usr/bin/cc
[root@sourcecode build]# mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
[root@sourcecode build]# ln -s /u01/export/gcc-11.3.0/lib64/libstdc++.so.6.0.29 /usr/lib64/libstdc++.so.6
[root@sourcecode build]#

6 Verify GCC Version Upgrade

Execute the following command to verify that GCC has been successfully upgraded:

[root@sourcecode build]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/u01/export/gcc-11.3.0/libexec/gcc/x86_64-pc-linux-gnu/11.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/u01/export/gcc-11.3.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.3.0 (GCC)
Detailed Steps to Upgrade GCC Version on Linux 8

The above is the process of upgrading the GCC version.

——– Recommended Reading ——–

How to Use MySQL Shell for Database Backup and Recovery?

How to Solve Errors When Executing Large Transactions in InnoDB Cluster?

MySQL 8.2 InnoDB ReplicaSet Series: Detailed Explanation of InnoDB Cluster Read Replicas

MySQL 8.2 InnoDB ReplicaSet Series: Detailed Explanation of Master-Slave Replicas

Look! MySQL 8.2 Database Supports Read-Write Separation!

MySQL 8.0 Database Software Installation and Deployment

MySQL 8.0 Set Up Automatic Restart for Database

MySQL 8.0 Permission Explanation (1)

MySQL 8.0 Permission Explanation (2)

MySQL 8.0 mysqldump Detailed Explanation

MySQL 8.0 High Availability Based on Point-in-Time Replication

MySQL 8.0 High Availability Based on GTID Replication

MySQL 8.0 High Availability: Online Switching Between Normal Replication Mode and GTID Replication Mode

MySQL 8.0 High Availability: Detailed Explanation of Semi-Synchronous Replication

MySQL 8.0 High Availability: How to Solve Master-Slave Synchronization Errors Caused by Data Modification on Slave

Analysis of “Aborted Connection” in MySQL Error Logs

Let’s Talk About MySQL Enterprise Monitor

MySQL Database Master-Slave Data Verification and Synchronization Tools

Using pt-archiver for Database Archiving

MySQL Security: Audit Function

MySQL High Availability: Automatic Failover Feature for Asynchronous Connection Failures

MySQL Clone Plugin: Monitoring Clone Operations and Usage Restrictions

MySQL Shell Installation and Basic Usage

MySQL High Availability: InnoDB Cluster

MySQL 8.0.30 InnoDB Cluster Practice

MySQL Router Installation and Basic Usage

How to Achieve High Availability for MySQL Router Using Keepalived

MySQL InnoDB Cluster: How to Avoid Single Point of Failure for Router

Best Practices for InnoDB ClusterSet

Rolling Upgrade of MySQL MGR

Detailed Steps to Upgrade GCC Version on Linux 8
WeChat ID: NotesOfAlen
Follow Alen for more information

Leave a Comment