Skip to content

Install gcc 4.8.2 by recompiling source on off-line server with CentOS 6.4 Operating System #3

@linrio

Description

@linrio

My server in laboratory is off-line, I can not install any software or depends library by yum install or wget http://.... Fortunately, I have super-user privileges(my username is in the /etc/sudoers), it's help for installing gcc. Let's begin to install gcc-4.8.2.

  1. Make sure your system information, my OS(Operating System) is :
    Linux k20-1 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

  2. On your personal computer you download gcc 4.8.2 installation package _gcc-4.8.2.tar.gz
    _ from GCC. Then transport the package to your server by scp ./gcc-4.8.2.tar.gz /home/user/gcc.

  3. Decompress the package by $tar -zxvf gcc-4.8.2.tar.gz ( or by if $tar -jxvf gcc-4.8.2.tar.bz2 ). Then go to gcc-4.8.2 directory by $cd /home/user/gcc/gcc-4.8.2 to see what depends library we should download by $vi gcc-4.8.1/contrib/download_prerequisites . It shows that gcc-4.8.2 needs gmp-5.1.3, mpfr-3.1.2 and mpc-1.0.1.

  4. From ftp://ftp.gnu.org/gnu/gmp/ download GMP install package gmp-5.1.3 .tar.bz2.
    From mpfr to download MPFR install package mpfr-3.1.2.tar.gz.
    From multiprecision to download MPC install package mpc-1.0.1.tar.gz

  5. Decompress the GMP, MPFR and MPC packages by $tar -zxvf or $tar -jxvf. Then,
    Install GMP:

[llf@k20-1 ~]$ cd gmp-5.1.3
[llf@k20-1 ~]$ sudo ./configure
[llf@k20-1 ~]$ sudo make
[llf@k20-1 ~]$ sudo make check
[llf@k20-1 ~]$ sudo make install

Install MPFR:

[llf@k20-1 ~]$ cd mpfr-3.1.2
[llf@k20-1 ~]$ sudo ./configure  --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib
[llf@k20-1 ~]$ sudo make
[llf@k20-1 ~]$ sudo make check
[llf@k20-1 ~]$ sudo make install

Install MPC:

[llf@k20-1 ~]$ cd mpc-1.0.1
[llf@k20-1 ~]$ sudo ./configure  --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib  --with-mpfr-include=/usr/local/include --with-mpfr-lib=/usr/local/lib
[llf@k20-1 ~]$ sudo make
[llf@k20-1 ~]$ sudo make check
[llf@k20-1 ~]$ sudo make install
  1. Add the include and lib to ~/.bashrc,
$vi ~/.bashrc  then add
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/usr/local/include:$C_INCLUDE_PATH
to  at the end of file.
  1. Add the lib to share libraries. $sudo vi /etc/ld.so.conf adding the following to it:
/usr/local/lib
  1. Install gcc-4.8.2. Make gcc install directory $sudo mkdir /usr/local/gcc4.8.2. Then cd /home/user/gcc/gcc-4.8.2. Run,
[llf@k20-1 ~]$ mkdir build  
[llf@k20-1 ~]$ cd build  
[llf@k20-1 ~]$ sudo ../configure --prefix=/usr/local/gcc4.8.2 --enable-threads=posix --disable-checking --enable-languages=c,c++ --disable-multilib  --with-gmp-include=/usr/local/include --with-gmp-lib=/usr/local/lib  --with-mpfr-include=/usr/local/include --with-mpfr-lib=/usr/local/lib --with-mpc-include=/usr/local/include --with-mpc-lib=/usr/local/lib
[llf@k20-1 ~]$ sudo make
[llf@k20-1 ~]$ sudo make install
  1. The end result of sudo make is:
libtool: link: ranlib .libs/libatomic.a
libtool: link: ( cd ".libs" && rm -f "libatomic.la" && ln -s "../libatomic.la" "libatomic.la" )
true  DO=all multi-do # make
make[4]: Leaving directory `/home/llf/support/gcc/gcc-4.8.2/build/x86_64-unknown-linux-gnu/libatomic'
make[3]: Leaving directory `/home/llf/support/gcc/gcc-4.8.2/build/x86_64-unknown-linux-gnu/libatomic'
make[2]: Leaving directory `/home/llf/support/gcc/gcc-4.8.2/build/x86_64-unknown-linux-gnu/libatomic'
make[1]: Leaving directory `/home/llf/support/gcc/gcc-4.8.2/build'
  1. The end result of sudo make install is:
libtool: finish: PATH="/sbin:/bin:/usr/sbin:/usr/bin:/sbin" ldconfig -n /usr/local/gcc4.8.2/lib/../lib64
ldconfig: /usr/local/gcc4.8.2/lib/../lib64/libstdc++.so.6.0.18-gdb.py is not an ELF file - it has the wrong magic bytes at the start.

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/gcc4.8.2/lib/../lib64

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/home/llf/support/gcc/gcc-4.8.2/build/x86_64-unknown-linux-gnu/libatomic'
make[3]: Leaving directory `/home/llf/support/gcc/gcc-4.8.2/build/x86_64-unknown-linux-gnu/libatomic'
make[2]: Leaving directory `/home/llf/support/gcc/gcc-4.8.2/build/x86_64-unknown-linux-gnu/libatomic'
make[1]: Leaving directory `/home/llf/support/gcc/gcc-4.8.2/build'

  1. Create soft link.
[llf@k20-1 ~]$ sudo mkdir /usr/gcc4.4.7backup/ 
[llf@k20-1 ~]$ sudo mv /usr/bin/{gcc,g++} /usr/gcc4.4.7backup
[llf@k20-1 ~]$ ln -s /usr/local/gcc4.8.2/bin/gcc  /usr/bin/gcc
[llf@k20-1 ~]$ ln -s /usr/local/gcc4.8.2/bin/g++ /usr/bin/g++
[llf@k20-1 ~]$ gcc -v
It will show your new version of GCC.

It's batter to create a README.md in /usr/gcc4.4.7backup in case other users need to use old gcc version gcc-4.4.7:

[llf@k20-1 ~]$ vi /usr/gcc4.4.7backup/README.md
writing: if you want to use gcc-4.4.7. Please 
[llf@k20-1 ~]$ sudo mv /usr/gcc4.4.7backup/{gcc,g++} /usr/bin

Reference from 1, 2, 2, 4

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions