Location>code7788 >text

Install gcc7.5.0 on centos7 system by compiling.

Popularity:498 ℃/2024-08-06 14:58:18

Background:

The highest version of the existing centos7 gcc is 4.8.5 The project needs to be upgraded to 7.1.0 or above The upgrade can be done in the normal way with the following commands:

$ sudo yum install centos-release-scl
$ sudo yum install devtoolset-7-gcc*
$ scl enable devtoolset-7 bash

Note: The third instructionscl enable devtoolset-7It just upgrades gcc in the current session, if you want to upgrade gcc automatically every time you log in, you can set thescl enable devtoolset-7put together ~/.bash_profile Documentation.

But recently centos official mirror can not be accessed normally, and aliyun and other domestic yum cloud does not seem to have the latest gcc version of the mirror, so you need to manually compile the way to install gcc The following version 7.5.0 as an example, if you need a higher version of the method is the same.

Download the installer at this address /gnu/gcc/gcc-7.5.0/gcc-7.5.

Upload to the server /usr/local directory

Execute the command to decompress

$ tar -zxvf ./gcc-7.5.0.tar.gz
$ cd gcc-7.5.0

 

The normal procedure is to run . /contrib/download_prerequisites to download the dependencies, but because of network problems, you can't download them directly, so you need to manually go to the website and upload them to the server at :

/pub/gcc/infrastructure/

Execute the command vim . /contrib/download_prerequisites

Open . /contrib/download_prerequisites to see the specific versions of the dependencies. There are four files, namely

gmp='gmp-6.1..bz2'
mpfr='mpfr-3.1..bz2'
mpc='mpc-1.0.'
isl='isl-0.16..bz2'

Download it and import it into the /usr/local/gcc-7.5.0 directory.

Install lbzip2 (decompression tool)

$ yum install -y lbzip2

execute a command

$  ./contrib/download_prerequisites

Configuration and Compilation

$ mkdir build
​
$ cd build
​
$ ../configure --prefix=/usr/local/gcc-7.5.0 --enable-languages=c,c++ --disable-multilib
​
$ make -j$(nproc)
$ sudo make install

 

Updating the PATH

$ export PATH=/usr/local/gcc-7.5.0/bin:$PATH

 

connect the aboveexport PATH command is added to your~/.bashrc maybe~/.bash_profile file to make it permanent.

Check the installed GCC version with the following command:

$ gcc --version