How to Install GCC on Red Hat Enterprise Linux 9

How to Install GCC on Red Hat Enterprise Linux 9

What is GCC? GCC stands for GNU Compiler Collection. This refers to a complete suite of tools. It is an integrated distribution of compilers. Which languages are these? This includes C, C++, objective-c, objective C++, Fortran, Ada, D, Rust, GO, and BRIG (HSAIL). It is a cross-platform compiler and was written by Richard Stallman in 1987. It is free software and available to install under GNU General Public License.

In this guide, we will walk you through to install GCC compiler on Red Hat Enterprise Linux 9. We will also demonstrate the working of GCC by compiling a simple program and running it on the terminal.

Prerequisites

  • RHEL 9 instance
  • Root account or a user with sudo privileges

Install GCC on Red Hat Enterprise Linux 9

In order to install GCC on Red Hat Enerprise Linux 9, you would run on the terminal:

Sudo yum install gcc

Check GCC version

You can verify the installation of GCC by checking its version installed on your machine, run:

gcc --version

As you can see from the above screenshot, GCC 11.4 has been successfully installed on the machine.

Compile a C program

Let’s compile a simple hello world C program with gcc compiler. Open any editor (I’m using nano) and write the following code. Save the file with .c extension (helloworld.c) in your current directory.

#include <stdio.h> 

void main(void)

{

printf ("Hello World!\n");

}

In the terminal, run:

gcc -o helloworld helloworld.c

When a program runs, it prints “Hello World!” on the terminal.

./helloworld

Conclusion

We have successfully installed and showed you the working of GCC on Red Hat Enterprise Linux 9. For more information about GCC, visit their official page.

For more how-tos and tutorials, please keep visiting Linux World.