This tutorial intends to teach you How To Install the GCC Compiler on Rocky Linux 8. Also, you will learn to test your GCC by creating a sample project.
GCC stands for “GNU Compiler Collection”. GCC is an integrated distribution of compilers for several major programming languages. These languages currently include C, C++, Objective-C, Objective-C++, Java, Fortran, and Ada.
Steps To Install GCC Compiler Collection on Rocky Linux 8
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Rocky Linux 8.
Install GCC Compiler on Rocky Linux 8
First, you need to update your local package index with the following command:
# sudo dnf update -y
# sudo dnf clean all
The GCC compiler packages are available in the package group called “Development tools“.
Development tools are the tools that are required to build applications or libraries for GNU/Linux.
You can check that you have the development tools are installed on your system, by using the command below:
sudo dnf group list
Output
Available Environment Groups:
Server with GUI
Server
Workstation
Virtualization Host
Custom Operating System
Installed Environment Groups:
Minimal Install
Available Groups:
Container Management
.NET Core Development
RPM Development Tools
Development Tools
Graphical Administration Tools
Headless Management
Legacy UNIX Compatibility
Network Servers
Scientific Support
Security Tools
Smart Card Support
System Tools
If the Development Tools is not listed, you will need to install it by running the following command:
sudo dnf group install "Development Tools"
Once the compiler and its package are installed, use the following command to show all information about the Development Tools:
sudo dnf group info "Development Tools"
Output
Group: Development Tools
Description: A basic development environment.
Mandatory Packages:
autoconf
automake
binutils
bison
flex
gcc
gcc-c++
gdb
glibc-devel
libtool
make
pkgconf
pkgconf-m4
pkgconf-pkg-config
redhat-rpm-config
rpm-build
rpm-sign
strace
Default Packages:
asciidoc
byacc
ctags
diffstat
elfutils-libelf-devel
git
intltool
jna
ltrace
patchutils
perl-Fedora-VSP
perl-Sys-Syslog
perl-generators
pesign
source-highlight
systemtap
valgrind
valgrind-devel
Optional Packages:
cmake
expect
rpmdevtools
rpmlint
Then, verify your GCC installation on Rocky Linux 8 by checking its version:
gcc --version
Output
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-15)
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.
To see the installation path of GCC, you can use the command below:
whereis gcc
Output
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz /usr/share/info/gcc.info.gz
Create a Sample project with GCC Compiler
At this point, you can test your GCC compiler by craeting a sample project.
First, create a file called “hello.c” in your home directory with your favorite text editor, here we use vi:
cd && sudo vi hello.c
Add the following content to the file:
#include <stdio.h>
int main() {
printf("OrcaCore, Hello world!\n");
return 0;
}
When you are done, save and close the file.
Next, compile the “hello.c” source code with the GCC compiler on Rocky Linux 8 by using the following command:
gcc hello.c -o helloworld
Then, run the executable helloword file:
./helloworld
In your output you should see:
Output
OrcaCore, Hello world!
Conclusion
At this point, you have learned to Install GCC Compiler on Rocky Linux 8 and create a test program with it.
Hope you enjoy it.
You may be like these articles:
Install and Use Golang on Centos 7