Friday, August 5, 2016

How to install gcc-6 in CentOS / RHEL Server

How to install gcc-6 in CentOS / RHEL x86_64 machine.

GCC used to stand for the GNU C Compiler, but since the compiler supports several other languages aside from C, it now stands for the GNU Compiler Collection.
GMP, MPFR and MPC libraries can be automatically built together with GCC. You may simply run the contrib/download_prerequisites script in the GCC source directory to set up everything

My Installation:
path = /opt
linux = CentOS 6
Arch = x86_64

Download gcc from one the below mirror sites which is nearby.
https://gcc.gnu.org/mirrors.html

[root@server1 ~]# cd /opt
[root@server1 ~]# tar xzf gcc-6.1.0.tar.gz  | untar gcc.
[root@server1 ~]# cd gcc-6.1.0
[root@server1 ~]# ./contrib/download_prerequisites
Note: It will download the pre request for gcc like GMP, MPFR, MPC etc.
[root@server1 ~]# cd ..
[root@server1 ~]# mkdir build
[root@server1 ~]# cd build
[root@server1 ~]# /opt/gcc-6.1.0/configure --prefix=/opt/gcc/gcc6 --enable-languages=c,c++,fortran,go,objc,obj-c++

Note: prefix is the build directory where the libraries are going to compile. simply its output folder. please modify your path.

[root@server1 ~]# make

Note: Make command runs 4 hours for me in 16GB RAM, 4 core Intel Xeon Server. It depends on ur machine config.

[root@server1 ~]# make install

That's it. your done.

If successfully installed:

[root@server1 ~]# /opt/gcc/gcc6/bin/gcc --version
gcc (GCC) 6.1.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@server1 ~]# /opt/gcc/gcc6/bin/g++ --version
g++ (GCC) 6.1.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If your build fails and your configure command has lots of complicated options you should try removing options and keep it simple. Do not add lots of configure options you don't understand, they might be the reason your build fails.

Total time : 5 hours.

Hope it helps.

Let me know if any doubts or questions.