How Do I Install GCC 7.3.0?
Perform the following steps as the root user.
- 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.
- To install GCC, you need to reserve adequate temporary space. You can run the following command to clear the /tmp directory in advance:
sudo rm -rf /tmp/*
- Install the dependency.
For CentOS/BCLinux, run the following command:
yum install bzip2
For Ubuntu/Debian, run the following command:
apt-get install bzip2
- Build and install GCC.
- Go to the directory where the source code package gcc-7.3.0.tar.gz is located and run the following command to decompress it:
tar -zxvf gcc-7.3.0.tar.gz
- Go to the decompressed folder and download the GCC dependency package:
cd gcc-7.3.0 ./contrib/download_prerequisites
If an error is reported during the command execution, run the following commands to download the dependency package from the gcc-7.3.0/ folder:
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 downloading the preceding dependency packages, run the following command:
./contrib/download_prerequisites
If the verification fails, check whether the dependency package is repeatedly downloaded. The package should be downloaded at a time.
- Run the following commands for configuration, build, and installation.
./configure --enable-languages=c,c++ --disable-multilib --with-system-zlib --prefix=/usr/local/gcc7.3.0 make -j15 # The value 15 indicates the number of CPUs, which is configurable and can be queried by running grep -w processor /proc/cpuinfo|wc -l. make install
The --prefix parameter is used to specify the GCC 7.3.0 installation path, which is configurable. Do not set it to /usr/local or /usr, which is the default installation path for the GCC installed by using the software source. Otherwise, a conflict occurs and the original GCC compilation environment of the system is damaged. In this example, the installation path is set to /usr/local/gcc7.3.0.
- Go to the directory where the source code package gcc-7.3.0.tar.gz is located and run the following command to decompress it:
- Set the environment variable.
The compilation environment after GCC upgrade is required for training. Therefore, you need to configure the following environment variable in the training script:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{install_path}/lib64
{install_path} indicates the GCC 7.3.0 installation path configured in 3, that is, /usr/local/gcc7.3.0/ in this example.
The environment variable needs to be configured only when you need to use the compilation environment after the GCC upgrade.