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? How can I install GCC (C and C++ Compiler) and development tools on a CentOS or RHEL 7?

You can setup a basic development environment with the following packages on a CentOS Enterprise Linux or Red Hat Enterprise Linux version 7:
Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements None
Time 5m

ADVERTISEMENTS

CentOS / RHEL 7: Install GCC Package list

  1. autoconf
  2. automake
  3. binutils
  4. bison
  5. flex
  6. gcc (c compiler)
  7. gcc-c++ (c++ compiler)
  8. gettext
  9. libtool
  10. make
  11. patch
  12. pkgconfig
  13. redhat-rpm-config
  14. rpm-build
  15. rpm-sign

Installing GCC c and c++

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

Another option:
# yum group list ids
Sample outputs:

Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * epel: mirror01.idc.hinet.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Available Environment Groups:
   Minimal Install (minimal)
   Compute Node (compute-node-environment)
   Infrastructure Server (infrastructure-server-environment)
   File and Print Server (file-print-server-environment)
   MATE Desktop (mate-desktop-environment)
   Basic Web Server (web-server-environment)
   Virtualization Host (virtualization-host-environment)
   Server with GUI (graphical-server-environment)
   GNOME Desktop (gnome-desktop-environment)
   KDE Plasma Workspaces (kde-desktop-environment)
   Development and Creative Workstation (developer-workstation-environment)
Available Groups:
   CIFS file server (cifs-file-server)
   Compatibility Libraries (compat-libraries)
   Console Internet Tools (console-internet)
   Desktop (basic-desktop)
   Desktop Platform (desktop-platform)
   Desktop Platform Development (desktop-platform-devel)
   Development Tools (development)
   Eclipse (eclipse)
   Educational Software (education)
   Electronic Lab (electronic-lab)
   FCoE Storage Client (storage-client-fcoe)
   Fedora Packager (fedora-packager)
   General Purpose Desktop (general-desktop)
   Graphical Administration Tools (graphical-admin-tools)
   Haskell (haskell)
   Legacy UNIX Compatibility (legacy-unix)
   Messaging Client Support (system-management-messaging-client)
   Messaging Server Support (system-management-messaging-server)
   Milkymist (milkymist)
   MySQL Database client (mysql-client)
   MySQL Database server (mysql)
   NFS file server (nfs-file-server)
   Network Storage Server (storage-server)
   SNMP Support (system-management-snmp)
   Scientific Support (scientific)
   Security Tools (security-tools)
   Server Platform (server-platform)
   Server Platform Development (server-platform-devel)
   Smart Card Support (smart-card)
   Storage Availability Tools (storage-client-multipath)
   System Administration Tools (system-admin-tools)
   System Management (system-management)
   TeX support (tex)
   TurboGears application framework (turbogears)
   Virtualization (virtualization)
   Web-Based Enterprise Management (system-management-wbem)
   Xfce (xfce-desktop)
   iSCSI Storage Client (storage-client-iscsi)
Done

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

Type the following yum command 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

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"
OR
# yum --setopt=group_package_types=mandatory,default,optional group install "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!
CentOS RHEL 7 Install GCC Compiler And Test It

A note about install man pages on a CentOS 6/7

Use the yum command as follows:
$ ## [ CentOS 7 ] ##
$ sudo yum install man-pages man-db man
$ ## [ CentOS 6.x ] ##
$ sudo yum install man man-pages

Conclusion

You learned how to install GNU c, c++ compilers and releated tools on a CentOS or Red Hat Enterprise Linux version 7.x. See GCC site for more info.

This entry is 3 of 13 in the Linux GNU/GCC Compilers Tutorial series. Keep reading the rest of the series:
  1. Ubuntu Linux Install GNU GCC Compiler and Development Environment
  2. Debian Linux Install GNU GCC Compiler and Development Environment
  3. CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools
  4. Download and Install C, C++ Compiler on Red Hat Enterprise Linux 5 (RHEL)
  5. Mac OS X: Install GCC Compiler with Xcode
  6. Where is My Linux GNU C or GCC Compilers Are Installed?
  7. HowTo: Compile And Run a C/C++ Code In Linux
  8. RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers
  9. HowTo Compiling C Program And Creating Executable File Under a Linux / UNIX / *BSD
  10. How To Install ncurses Library on a Linux
  11. Linux Find Out What Compilers Are Installed or Available On The System
  12. Linux Find Out GNU gcc Compiler Version Used To Compile Running Kernel
  13. Howto see output of C program in Linux or UNIX
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
17 comments… add one
  • danilo Jul 14, 2014 @ 20:53

    Just use yum install gcc*

    It will install all gcc software and upgrade all the files to satisfy dependices

  • kirti Oct 21, 2014 @ 7:09

    We should have no space between group and install.
    # yum groupinstall "Development Tools"

    Please update.
    Thanks

  • greendruid Oct 29, 2014 @ 10:17

    Please, fix ‘group install‘ -> ‘groupinstall‘.
    For example:
    yum groupinstall "Development Tools"

  • xfree Nov 27, 2014 @ 3:44

    yum group install "Development Tools"
    right is
    yum groupinstall "Development Tools"

    • deadman Dec 18, 2014 @ 9:12

      yes, you is right

  • tom Jul 12, 2015 @ 0:26

    hello, i have a Problem with gcc, when i need
    when I run include command I get the following message:
    bash: syntax error near unexpected token `newline ‘

  • lata Jul 12, 2015 @ 17:28

    #yum install “development tools” is not working in centos 7

    • Mickey Dec 2, 2015 @ 17:54

      Use groupinstall as the article says…

      • Donavan May 3, 2016 @ 22:42

        for centos/rhel 7 use (missing the “s” off groups):
        yum groups install "Development Tools"

        Durring install if you get any errors regarding kernel packages ex:

        --> Finished Dependency Resolution
        Error: Package: systemtap-devel-2.8-10.el7.x86_64 (base)
                   Requires: kernel-devel
        

        All kernel packages are on the yum exclude list so you may need to do the following:
        yum -y install kernel-devel --disableexcludes=all

        to see all groups available:
        yum groups list

  • Richard Klein Jul 20, 2015 @ 17:30

    In Centos 7:
    Warning: Group development does not have any packages to install.

    • Mickey Dec 2, 2015 @ 17:55

      Put quotes around the “Development Tools” group name, as per the article (copy and paste is your friend)!

  • aref ghobadi Aug 15, 2015 @ 9:39

    I really appreciate your help

  • AlucarD Mar 4, 2016 @ 15:34

    on CentOS 7 you can try this( It is one line !!) :
    yum groupinstall "Development Tools" --setopt=group_package_types=mandatory,default,optional

    this is a yum setup.
    Have a nice day,
    AlucarD

    • vietsoft Apr 29, 2016 @ 0:27

      @AlucarD’s way is definitely works

  • boboc alexandru Sep 1, 2016 @ 14:34

    so, how do i became root? it says i have to be root to perform this action

  • Morvan Nov 13, 2016 @ 0:07

    Good evening.
    Hint from AlucarD saved my day:
    yum groupinstall "Development Tools" --setopt=group_package_types=mandatory,default,optional
    Now, my Server is optimal.

  • dAnarchy Nov 22, 2016 @ 10:00

    Wow this is great for automating installs, thanks for the info!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.