Make GCC by hand for CentOS7
Flu

In some cases, my Linux server cannot connect to the Internet while I have to upgrade the GCC on that server to use C++17 or higher. Unlike CMAKE, I have nowhere to download the prebuild binary version of the GCC. The only way is to upload all the necessary files and make them one by one.

Sounds boring. Here is what I did. I make notes about the steps incase I need it again.

0. Find a mirror

When you need to make GCC, you have to make some other libraries first. They are gmp-x.x.x.tar.gz, mpfr-x.x.x-tar.gz, mpc-x.x.x.tar.gz and of course you need gcc-x.x.x.tar.gz itself.

There are dependencies. Make sure to check the release date of all versions of libraries. The release date from early to late should be gmp < mpfr < mpc < gcc.

2. make gmp

1
2
3
4
5
tar xzf gmp-x.x.x.tar.gz
cd gmp-x.x.x
./configure --prefix=/path/to/gmp-x.x.x
make
make install

3. make mpfr

1
2
3
4
5
tar xzf mpfr-x.x.x.tar.gz
cd mpfr-x.x.x
./configure --prefix=/path/to/mpfr-x.x.x --with-gmp=/path/to/gmp-x.x.x
make
make install

4. make mpc

1
2
3
4
5
tar xzf mpc-x.x.x.tar.gz
cd mpc-x.x.x
./configure --prefix=/path/to/mpc-x.x.x --with-gmp=/path/to/gmp-x.x.x --with-mpfr=/path/to/mpfr-x.x.x
make
make install

5. set LD_LIBRARY_PATH

1
export LD_LIBRARY_PATH=/path/to/mpc-x.x.x/lib:/path/to/gmp-x.x.x/lib:/path/to/mpfr-x.x.x/lib:$LD_LIBRARY_PATH

6. make gcc

1
2
3
4
5
tar xzf gcc-x.x.x.tar.gz
cd gcc-x.x.x
./configure --prefix=/path/to/gcc-x.x.x --with-mpc=/path/to/mpc-x.x.x --with-gmp=/path/to/gmp-x.x.x --with-mpfr=/path/to/mpfr-x.x.x --disable-multilib
make
make install

Be patient. It takes 4-8 hours.

7. many exports

1
2
export PATH=/path/to/gcc-x.x.x/bin:$PATH
export LD_LIBRARY_PATH=/path/to/gcc-x.x.x/lib64:$LD_LIBRARY_PATH

8. Check if installed successfully

1
gcc --version

Now everything is finished. Congratulations.

FYI How to install cmake

Without Internet.

Go to CMake website and download file like this cmake-x.xx.x-linux-x86_64.tar.gz

1
2
3
4
5
tar -xvf cmake-x.xx.x-linux-x86_64.tar.gz
mv cmake-x.xx.x /usr/local/cmake
echo 'export PATH="/usr/local/cmake/bin:$PATH"'>>~/.bashrc
source ~/.bashrc
cmake --version
 Comments