How To Install GCC Compiler on AlmaLinux 9

In this guide, we want to teach you to Install GCC Compiler on AlmaLinux 9.

GCC is a set of compilers for various languages (Ada, C, C++, Fortran, ObjC, ObjC++, and at one point java). It provides all of the infrastructure for building software in those languages from source code to assembly.

It is responsible for the conversion of the “high-level” source code in the respective language and ensuring that it is semantically valid, performing well-formed optimizations, and converting it to assembly code.

Also, it provides the general “driver” to invoke the various tools in the toolchain, so that you do not need to worry about the exact ordering of a large number of implementation details about the object file format and underlying runtime library.

Steps To Install GCC Compiler on AlmaLinux 9

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 AlmaLinux 9.

Install GCC Compiler on AlmaLinux 9

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.

Developments Tools on AlmaLinux 9

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:
   RPM Development Tools
   .NET Development
   Container Management
   Console Internet Tools
   Development Tools
   Legacy UNIX Compatibility
   Graphical Administration Tools
   Network Servers
   Headless Management
   System Tools
   Security Tools
   Smart Card Support
   Scientific Support

If the Development Tools is not listed, you will need to install it by running the following command:

sudo dnf group install "Development Tools"

Check Development Tools Info

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
   diffstat
   git
   intltool
   jna
   ltrace
   patchutils
   perl-Fedora-VSP
   perl-generators
   pesign
   source-highlight
   systemtap
   valgrind
   valgrind-devel
 Optional Packages:
   cmake
   expect
   rpmdevtools
   rpmlint

Then, verify your GCC installation on AlmaLinux 9 by checking its version:

gcc --version
Output
gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2)
Copyright (C) 2021 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

Test GCC Compiler on AlmaLinux 9

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 AlmaLinux 9 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 AlmaLinux 9 and create a test program with it.

Hope you enjoy it. You may be like these articles:

Install and Configure WireGuard on AlmaLinux 9

Install Nagios Monitoring Tool on AlmaLinux 9

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!