environment
Linux version 3.10.0-1160.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020
Current gcc version 4.8.5
text
The required resources can be downloaded in the gnu installation package_Open Source Mirror Station-Alibaba Cloud Download
include:
- gcc-10.1.0
- gmp-5.0.1
- mpc-1.0.1
- mpfr-3.1.5
Unzip all
tar -vxf gmp-5.0.1.tar.bz2
tar -vxf mpfr-3.1.5.tar.xz
tar -vxf mpc-1.0.1.tar.gz
tar -vxf gcc-10.1.0.tar.gz
Create a directory under /user/local
[root@localhost local]# mkdir mpc-1.0.1
[root@localhost local]# mkdir gmp-5.0.1
[root@localhost local]# mkdir mpfr-3.1.5
Install gmp and return to the decompressed file directory: pay attention to check whether there is an error during execution, and if so, solve it.
[root@localhost soft]# cd gmp-5.0.1/
[root@localhost gmp-5.0.1]# ./configure --prefix=/usr/local/gmp-5.0.1[root@localhost gmp-5.0.1]# make
[root@localhost gmp-5.0.1]# make install
install mpfr
[root@localhost gmp-5.0.1]# cd ../mpfr-3.1.5/
[root@localhost mpfr-3.1.5]# ./configure --prefix=/usr/local/mpfr-3.1.5 --with-gmp=/usr/local/gmp-5.0.1[root@localhost mpfr-3.1.5]# make
[root@localhost mpfr-3.1.5]# make install
install mpc
[root@localhost gmp-5.0.1]# cd ../mpc-1.0.1/
[root@localhost mpfr-3.1.5]# ./configure --prefix=/usr/local/mpc-1.0.1 --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.5[root@localhost mpfr-3.1.5]# make
[root@localhost mpfr-3.1.5]# make install
Configure gcc
[root@localhost soft]# cd gcc-10.1.0/
[root@localhost gcc-10.1.0]# mkdir build
[root@localhost gcc-10.1.0]# cd build
[root@localhost gcc-10.1.0]# ../configure --prefix=/usr/local/gcc-10.1.0/ --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.5 --with-mpc=/usr/local/mpc-1.0.1[root@localhost gcc-10.1.0]# make -j4 //The time will be longer
[root@localhost gcc-10.1.0]# make inistall
Change the name of the previous version of gcc, because the version is 4.8.5, so change the name to 485
[root@localhost bin]# mv /usr/bin/gcc /usr/bin/gcc485
[root@localhost bin]# mv /usr/bin/g++ /usr/bin/g++485
[root@localhost bin]# mv /usr/bin/c++ /usr/bin/c++485
[root@localhost bin]# mv /usr/bin/cc /usr/bin/cc485
Link the newly configured gcc to the environment variable
[root@localhost bin]# ln -s /usr/local/gcc-10.1.0/bin/gcc /usr/bin/gcc
[root@localhost bin]# ln -s /usr/local/gcc-10.1.0/bin/g++ /usr/bin/g++
[root@localhost bin]# ln -s /usr/local/gcc-10.1.0/bin/c++ /usr/bin/c++
[root@localhost bin]# ln -s /usr/local/gcc-10.1.0/bin/gcc /usr/bin/cc
similar to above
[root@localhost bin]# mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
[root@localhost bin]# ln -s /usr/local/gcc-10.1.0/lib64/libstdc++.so.6.0.28 /usr/lib64/libstdc++.so.6
Finally check the gcc version
successfully upgraded
reference
The whole process of upgrading Linux gcc, the process is super detailed - Programmer Sought