Install GCC Compiler on Rocky Linux 8

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. You can use GCC to compile and build your programs. It has several languages such as C, C++, Objective-C, Objective-C++, Java, Fortran, and Ada.

How 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.

Now follow the steps below to complete this guide.

Step 1 – Run Rocky Linux 8 System Update

First, you need to update your local package index with the following command:

# sudo dnf update -y
# sudo dnf clean all

Step 2 – Enable Development Tools on Rocky Linux 8

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 in Linux.

First, check that you have installed this tool on your server or not with the following command:

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"

When your installation is completed, check your development tools info with the command below:

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

As you can see from the output, the GCC has been installed on your server.

Step 3 – Verify GCC Installation on Rocky Linux 8

At this point, you can 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

Step 3 – Create a Sample project with GCC Compiler

At this point, you can test your GCC compiler by creating a sample project.

First, create a file called “hello.c” in your home directory with your favorite text editor, here we use the vi editor:

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 hello word 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. GCC is a great compiler tool that includes many programming languages that you can use to compile and build your programs.

Hope you enjoy it. You may be like these articles on the Orcacore website:

Install and Use Golang on Centos 7

Install and Configure Django on Debian 11

How To Install Node.js on AlmaLinux 9

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!