Installing GCC c and c++
Command to list groups on a CentOS / RHEL 7
# yum group list
Another option:
# yum group list ids
Command to install GCC and Development Tools on a CentOS / RHEL 7 server:
# yum group install "Development Tools"
If above command failed, try:
# yum groupinstall "Development Tools"
A note about failing groupinstall on CentOS/RHEL 7.x:
To install all the packages belonging to a package group called “Development Tools” use the following command:
# yum --setopt=group_package_types=mandatory,default,optional groupinstall "Development Tools"
The yum has changed in Red Hat Enterprise Linux 7/CentOS 7. The package group “Development Tools”” has only the optional packages which by default doesn’t get installed. So we will need to pass the option —
setopt=group_package_types=mandatory,default,optional to install the optional packages too.
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!
Leave a Comment