Installing GCC
- Go to the specified directory and download the file. (The /opt/tools/installed directory is used as an example.)
cd /opt/tools/installed/ wget https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
- Decompress the source package.
tar -xf gcc-7.3.0.tar.gz
- Go to the source code directory and install bzip2.
cd gcc-7.3.0 yum install -y bzip2
- Download the dependency.
./contrib/download_prerequisites
- Ensure that the network is connected. If the download fails, you can manually download the file.
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
- After the manual download is complete, run the script again.
./contrib/download_prerequisites
- Ensure that the network is connected. If the download fails, you can manually download the file.
- Edit the configuration.
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/gcc7.3.0
- Perform compilation and installation.
make -j15 make install
- Set environment variables.
- Open the /etc/profile file.
vim /etc/profile
- Press i to enter the insert mode and add the commands at the end of the file:
export LD_LIBRARY_PATH=/usr/local/gcc7.3.0/lib64:${LD_LIBRARY_PATH} export CC=/usr/local/gcc7.3.0/bin/gcc export CXX=/usr/local/gcc7.3.0/bin/g++ - Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the /etc/profile file.
- Make the environment variables take effect.
source /etc/profile
- Verify the installation.
gcc -v

g++ -v

The installation path depends on the preceding configurations. You only need to pay attention to the version number.
Parent topic: Configuring the Compilation Environment