The objective of this guide is to install GCC the C compiler on RHEL 8 / CentOS 8 and perform compilation of a basic C "Hello World" program. The GCC compiler can be installed in RHEL 8 by simply using the dnf install command.

In this tutorial you will learn:
  • How to install GCC compiler on RHEL 8 / CentOS 8.
  • How to install Development Tools installation group.
  • How to write C program.
  • How to compile and execute C program.
GCC the C compiler on RHEL 8 and Hello world C program example.
GCC the C compiler on RHEL 8 and Hello world C program example.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software gcc
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

How to install GCC the C compiler on RHEL 8 / CentOS 8 step by step instructions


$$$ Looking for LINUX ADMINISTRATOR ! $$$

BLUE SKY STUDIOS are looking for Linux Administrator to maintain and support the Studio's 450+ production Linux workstations, including daily interactions with the Studio’s digital animation artists.
LOCATION: Greenwich, Connecticut, USA

APPLY NOW

  1. Use the dnf command and install the gcc package:
    # dnf install gcc
    
  2. (optional) Install Development Tools transitional group package.

    Another way to install the gcc compiler is to install it as part of the Development Tools transitional group package. Development Tools package will also install additional libraries as well as the g++ compiler. In most cases or if unsure this is exactly what you need:
    # dnf groupinstall "Development Tools"
    
  3. Check GCC version. Confirm your installation by checking for the GCC version:
    $ gcc --version
    gcc (GCC) 8.2.1 20180905 (Red Hat 8.2.1-3)
    
  4. (optional) Compile a simple C "Hello World" code:
    #include <stdio.h>
    int main()
    {
       printf("Hello, World!\n");
       return 0;
    }
    
    Save the above code within the hello.c file, compile and execute it:
    $ gcc -o hello hello.c 
    $ ./hello 
    Hello, World!
    
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.