GNU is the short-term GNU Compiler Collection, with compilers for computing languages such as C, Objective-C, Ada, C++, Go, Fortran, and many more. It is a famous compiler suite widely used in various Linux distros. GNU is developed under the GNU Project, aiming to create an open-source tool to replace traditional compilers.
GCC also supports many runtime libraries, including standard libraries of every programming language, math libraries, etc. That’s why GNU has become a crucial part of the Linux ecosystem, as it provides a versatile compiler suite for various programming languages. So in this guide, you will get to know about the complete method to install and use the GCC compiler in Rocky Linux 9.
How to Install the GCC Compiler on Rocky Linux 9
First, please update the system as per the latest utilities and repositories available for Rocky Linux 9:
Once you are done, please run the below command to install the GCC in the system:
GCC is the utility in Rocky Linux 9, so the above command will install its current version. Moreover, you can check the installed version of GCC through the following command:
In case you want to install GCC-C++, which is its C++ compiler component, please run the following command:
Now, let’s take a look at the ways to use GCC on Rocky Linux 9 through some examples.
How to Use GCC Compiler [Examples]
Here we will write and compile a C program using the GCC compiler, so please run the below command to open a text editor:
After opening the text editor, you can write a program that shows the sum of two numbers:
int main() {
int n1, n2, sum;
printf("Please enter numbers: ");
scanf("%d %d", &num1, &num2);
sum = n1 + n2;
printf(" The sum of given numbers is: %d\n", sum);
return 0;
}
Once you write the program, save and exit the text editor. Now, let’s add the program file to GCC and name it “sum”:
In the above command, we have used the -o option to show the output filename.
Finally, run the following command to compile the C program right from the terminal:
Similarly, you can compile programs of programming languages, so all you need to do is create a program and add it to GCC.
Wrapping Up
So this was all about the simple way to install and use GCC Compiler on Rocky Linux 9. We have executed a C program to show how to use the GCC Compiler from the terminal. GCC supports various languages, so please follow the above guide to compile those programs with no issues.