Rate This Document
Findability
Accuracy
Completeness
Readability

Installing GCC

  1. 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
  2. Decompress the source package.
    tar -xf gcc-7.3.0.tar.gz
  3. Go to the source code directory and install bzip2.
    cd gcc-7.3.0
    yum install -y bzip2
  4. Download the dependency.
    ./contrib/download_prerequisites
    1. 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
    2. After the manual download is complete, run the script again.
      ./contrib/download_prerequisites
  5. Edit the configuration.
    ./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/gcc7.3.0
  6. Perform compilation and installation.
    make -j15
    make install
  7. Set environment variables.
    1. Open the /etc/profile file.
      vim /etc/profile
    2. 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++
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  8. Make the environment variables take effect.
    source /etc/profile
  9. 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.