How to install GCC (development tools) on CentOS 8

The GNU Compiler Collection (GCC) is a collection of compilers and libraries for the C, C ++, Objective-C, Fortran, Ada, Go, and D programming languages. Many open source projects, including the Linux kernel and GNU tools, are compiled using GCC.

This article describes how to install GCC on CentOS 8.

Installing GCC on CentOS

The CentOS repositories contain a group of packages called “Development Tools” by default, which includes the GNU Compiler Collection, the GNU Debugger and other development libraries and tools needed to compile software.

To install development kits, run the following command as root or a user with sudo privileges:

sudo dnf group install "Development Tools"

The command installs many packages, including gcc, g ++ and make.

You can also install the GNU / Linux development manual pages:

sudo dnf install man-pages

Verify that the GCC compiler is successfully installed using the gcc –version command, which prints the GCC version:

gcc --version

The default GCC version available in the CentOS 8 8.3.1 repositories:

gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)
Copyright (C) 2018 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.

That’s all. GCC is installed on your CentOS system and you can start using it.

Compiling the Hello World example

In this section, we will compile a basic C program using GCC. Open your text editor and create the following file:

nano hello.c

#include <stdio.h>
int main()
{
  printf ("Привет мир!n");
  return 0;
}

Save the file and compile it into an executable file by running:

gcc hello.c -o hello

A binary file named hello will be created in the same directory where you run the command.

Run the hello program:

./hello

The program will output:

Привет мир!

Output

We showed you how to install GCC on CentOS 8. Now you can visit the official GCC documentation page and learn how to use GCC and G ++ to compile your C and C ++ programs.

If you run into an issue or have feedback, please leave a comment below.

Sidebar