Wednesday, June 25, 2014

CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools

How do I install gnu gcc compiler and related tools such as autoconf, automake, flex, c++ compiler, and bison on a CentOS 7 or Red Hat Enterprise Linux version 7 server?

You can setup a basic development environment with the following packages on a CentOS Enterprise Linux or Red Hat Enterprise Linux version 7:



  1. autoconf
  2. automake
  3. binutils
  4. bison
  5. flex
  6. gcc
  7. gcc-c++
  8. gettext
  9. libtool
  10. make
  11. patch
  12. pkgconfig
  13. redhat-rpm-config
  14. rpm-build
  15. rpm-sign
Open the Terminal app and type the following commands.

Command to list groups on a CentOS / RHEL 7

Type the following yum command:
# yum group list
Sample outputs:
Fig. 01: CentOS / RHEL 7: List Package Groups Command
Fig. 01: CentOS / RHEL 7: List Package Groups Command

Command to install GCC and Development Tools on a CentOS / RHEL 7 server

Type the following [nixcmd name="yum" as root user:
# yum group install "Development Tools"
OR
$ sudo yum group install "Development Tools"
If above command failed, try:
# yum groupinstall "Development Tools"
Sample outputs:
Animated gif.01: Installing C & C++ and related packages on a CentOS and RHEL 7
Animated gif 01: Installing C & C++ and related packages on a CentOS and RHEL 7

Verify your gcc installation on a CentOS / RHEL 7 server

Type the following command to see gcc location:
$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
Type the following command to see gcc compiler version:
$ gcc --version
gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)
Copyright (C) 2013 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.

Test gcc C compiler with a sample foo.c program

Create a file called foo.c as follows:
 
#include<stdio.h>
int main(void){
 printf("Hello World!\n");
 return 0;
}
 
To compile foo.c into foo executable file, type:
$ cc foo.c -o foo
To execute foo program, type:
$ ./foo
Hello World!

0 comments:

Post a Comment