Installing GCC 7.3.0

GCC is a basic tool. If it is installed by multiple users, conflicts may occur. Therefore, you are advised to perform the following steps as the root user.

  1. Download gcc-7.3.0.tar.gz from https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz.
  2. The GCC installation occupies a large amount of temporary space. Therefore, run the following command to clear the /tmp directory:
    1
    rm -rf /tmp/*
    
  3. Install the dependency package. (CentOS and Ubuntu are used as examples.)
    • For CentOS, run the following command:
      1
      yum install bzip2    
      
    • For Ubuntu, run the following command:
      1
      apt-get install bzip2    
      
  4. Compile and install GCC.
    1. Go to the directory where the source package gcc-7.3.0.tar.gz is located and run the following command to decompress it:
      1
      tar -zxvf gcc-7.3.0.tar.gz --no-same-owner
      
    2. Go to the decompressed folder and download the GCC dependencies:
      1
      2
      cd gcc-7.3.0
      ./contrib/download_prerequisites
      

      If an error is reported during the execution of the preceding command, run the following commands to download the dependencies in the gcc-7.3.0/ folder:

      1
      2
      3
      4
      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 preceding dependencies are downloaded, run the following command again:

      1
      ./contrib/download_prerequisites
      

      If the preceding command fails, ensure that the dependencies are successfully downloaded at a time and no repeated download occurs.

    3. Run the configuration command.
      1
      ./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/gcc7.3.0
      

      The --prefix parameter is used to specify the GCC 7.3.0 installation path. You can set it as required. However, do not set it to /usr/local or /usr because they conflict with the GCC that is installed by default by the system using the software source. Otherwise, the original GCC compilation environment of the system will be damaged. In this example, use /usr/local/gcc7.3.0.

    4. Perform compilation.
      1
      make -j15    # Check the number of CPUs by running grep -w processor /proc/cpuinfo|wc -l. In this example, the number is 15. You can set the parameter as required.
      
    5. Perform the installation.
      1
      make install
      
  5. Configure environment variables as required.
    1
    2
    3
    4
    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++
    export PATH=/usr/local/gcc7.3.0/bin:${PATH}
    

    In the preceding command, /usr/local/gcc7.3.0 indicates the GCC 7.3.0 installation path configured in 4.c. Replace it with the actual path.