The GNU Compiler Collection is a collection of compilers and libraries for language development, including: C, C++, Objective-C, Fortran, Ada, Go, and D programming languages. Many open source projects, including Linux kernel and GNU tools, are compiled using GCC.
This article describes how to install GCC on CentOS 8.
The default CentOS software source contains a package group named "Development Tools", which contains the GNU editor collection, GNU debugger, and other development libraries and tools necessary for compiling software.
To install the development tool package, run the following command as a user with sudo privileges or as root:
sudo dnf group install "Development Tools"
This command will install a series of packages, including gcc
, g++
, and make
.
You may also want to install a manual on how to use GNU/Linux development.
sudo dnf install man-pages
Use the gcc --version
command to print the GCC version to verify whether the GCC compiler is successfully installed:
gcc --version
The default available version number of GCC in the CentOS 8 software source is 8.3.1
:
gcc(GCC)8.3.120190507(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 it. GCC has been installed on your CentOS system, and you can start using it.
In this chapter, we will use GCC to compile a basic C program. Open your text editor and create the following file:
nano hello.c
# include <stdio.h>
int main(){printf("Hello World!\n");return0;}
Save the file, and compile it into an executable file, run:
gcc hello.c -o hello
When you run this command, a binary file named hello
will be created in the same directory.
Execute this hello
program:
. /hello
This program will output:
Hello World!
We have shown how to install GCC on CentOS 8. You can now browse the official GCC documentation page and learn how to use GCC and G++ to compile your C and C++ programs.
Recommended Posts