RHEL BasedRocky Linux

How To Install GCC on Rocky Linux 10

Install GCC on Rocky Linux 10

If you run a Rocky Linux 10 server and need to compile C, C++, or other programs from source, the first tool you need is GCC (GNU Compiler Collection). GCC is the standard compiler for Linux systems and the backbone of almost every software build process. This guide shows you exactly how to install GCC on Rocky Linux 10 using three proven methods, verify the installation, compile a test program, and fix common errors that trip up even experienced sysadmins. Whether you are setting up a fresh development server or adding a compiler to an existing production box, you will have a working GCC environment by the time you finish reading.

What Is GCC and Why Does Your Rocky Linux 10 Server Need It?

GCC stands for GNU Compiler Collection. It is a free, open-source suite of compilers maintained by the GNU Project that supports C, C++, Fortran, Go, Objective-C, and more.

Rocky Linux 10 ships with GCC 13 as its default system compiler, a significant step up from GCC 11 in Rocky Linux 9. GCC 13 brings full C17 support, improved C++23 capabilities, better optimization passes, and stronger static analysis warnings, all of which matter for production build environments.

Here is what you will typically use GCC for on a Rocky Linux 10 server:

  • Compiling software from source that is not available as a pre-built RPM
  • Building kernel modules and custom drivers
  • Developing and testing C or C++ applications directly on the server
  • Packaging software using rpmbuild, which depends on GCC internally
  • Running CI/CD build pipelines on a self-hosted runner

If you try to run gcc on a fresh minimal install of Rocky Linux 10, you will get a “command not found” error. The minimal install profile does not include GCC by default. This guide solves that problem in three different ways so you can pick the one that fits your situation.

Prerequisites

Before you start the GCC on Rocky Linux 10 setup, confirm that your environment meets these requirements:

  • Operating system: Rocky Linux 10 (any point release, including 10.1)
  • User privileges: A sudo-enabled user account or direct root access
  • Network access: Your server must reach the Rocky Linux AppStream and BaseOS repositories
  • Package manager: Rocky Linux 10 uses dnf — all commands in this guide use dnf, not the older yum
  • Disk space: At least 500 MB of free space for the Development Tools group install; the single gcc package requires roughly 50 MB
  • Terminal access: SSH session, console, or any terminal emulator connected to your server

No prior GCC experience is required. If you can log in to a Linux server and run sudo commands, you are ready.

Step 1: Check If GCC Is Already Installed

Before installing anything, check whether GCC is already present on your system. Some Rocky Linux 10 install profiles like “Server with GUI” or “Workstation” may include it.

Run this command:

which gcc

If GCC is installed, this returns the path to the binary, typically /usr/bin/gcc. If the terminal outputs “no gcc in…” or simply returns nothing, GCC is not installed.

Now check the version to confirm what you have:

gcc --version

Expected output on Rocky Linux 10:

gcc (GCC) 13.3.1 20240522 (Red Hat 13.3.1-1)
Copyright (C) 2023 Free Software Foundation, Inc.

If you see GCC 13.x output, your system already has GCC and you can skip ahead to the verification section. If not, continue with the installation methods below.

Step 2: Update Your System Before Installing GCC

Always update your package metadata and installed packages before adding new software. This avoids dependency conflicts and makes sure dnf pulls the latest GCC 13 build from the repository.

Run these two commands in order:

sudo dnf clean all
sudo dnf update -y

What these commands do:

  • dnf clean all wipes cached package metadata and downloaded files, forcing dnf to fetch fresh data on the next operation
  • dnf update -y upgrades all installed packages to their latest versions and answers “yes” to all prompts automatically with the -y flag

Wait for the update to finish. On a fresh minimal install this usually takes one to three minutes depending on your connection speed. Reboot if the kernel was updated:

sudo reboot

Reconnect via SSH after the server comes back online before proceeding.

Step 3: Install GCC on Rocky Linux 10 via DNF (Single Package Method)

This is the fastest way to install GCC on Rocky Linux 10. Use this method when you need only the C compiler and do not want to pull in a large bundle of extra tools.

Install the GCC C Compiler

sudo dnf install gcc -y

DNF resolves all dependencies automatically and installs the gcc package along with required libraries.

Install the GCC C++ Compiler (Recommended)

The gcc package covers C compilation only. For C++ development, install gcc-c++ separately:

sudo dnf install gcc-c++ -y

On Rocky Linux 10, gcc-c++ is a separate RPM that provides the g++ frontend to GCC. Both gcc and gcc-c++ share the same underlying GCC 13 toolchain.

What to expect in the terminal:

Dependencies resolved.
================================================================================
 Package         Architecture   Version             Repository            Size
================================================================================
Installing:
 gcc             x86_64         13.3.1-1.el10       appstream             25 M

Transaction Summary
================================================================================
Install  1 Package

Complete!

After the install finishes, verify with:

gcc --version
g++ --version

Both should report GCC 13.x.

Step 4: Install GCC via the Development Tools Group (Full Environment Method)

If you are setting up a full development server, the “Development Tools” group is a much better choice than installing packages one by one. This group bundles GCC with make, autoconf, automake, libtool, rpmbuild, patch, git, and a dozen other essential tools that you will need the moment you start building real software from source.

Confirm the Group Is Available

sudo dnf group list

Scan the output for “Development Tools” under the “Available Groups” or “Installed Groups” section.

Install the Development Tools Group

sudo dnf groupinstall "Development Tools" -y

If that command returns an error, use the alternative syntax:

sudo dnf group install "Development Tools" -y

Both forms are equivalent on Rocky Linux 10. The install process will download and install between 15 and 30 packages depending on what is already on your system.

Confirm What Got Installed

dnf groupinfo "Development Tools"

This lists every package that belongs to the group and marks each one as “Installed” or “Available.” Check that gcc and gcc-c++ both appear as installed.

This method is the recommended configure GCC on Rocky Linux 10 approach for anyone doing serious development or packaging work on the server. Installing the full group now saves you from chasing down missing dependencies later.

Step 5: Install a Specific GCC Version via GCC Toolset (Advanced Method)

Some projects require a GCC version that is different from the system default. Rocky Linux 10 supports GCC Toolsets, which are Software Collections-style packages that let multiple GCC versions coexist on the same system without replacing the system compiler.

This is the right approach when you need GCC 12 or GCC 14 alongside the default GCC 13, or when a legacy codebase requires a specific compiler version.

Search for Available Toolsets

sudo dnf search gcc-toolset

This returns a list of available GCC toolset packages in the AppStream repository.

Install a GCC Toolset

To install GCC Toolset 13 (the same version as system GCC but with additional developer tools):

sudo dnf install gcc-toolset-13-toolchain -y

For a different version, replace 13 with the version number you need, such as gcc-toolset-12-toolchain.

Enable the Toolset in Your Current Shell

scl enable gcc-toolset-13 bash

This opens a new bash subshell where gcc resolves to the toolset version rather than the system default.

If scl is not found, install it first:

sudo dnf install scl-utils -y

Make the Toolset Permanent (Optional)

To activate the toolset every time a specific user logs in, add the enable command to their shell profile:

echo "source scl_source enable gcc-toolset-13" >> ~/.bashrc
source ~/.bashrc

Confirm the Active GCC Version

gcc --version
scl list-collections

scl list-collections shows all currently installed Software Collections on your system.

Step 6: Verify the Installation and Compile a Test Program

After installing GCC on Rocky Linux 10 using any of the three methods above, run a real compilation test. Checking the version number is not enough — you want to confirm that the compiler can actually build a binary.

Create a Simple C Program

nano hello.c

Enter the following code exactly:

#include <stdio.h>
int main() {
    printf("Hello from Rocky Linux 10!\n");
    return 0;
}

Save and exit: press Ctrl+X, then Y, then Enter.

Compile the Program

gcc hello.c -o hello

What this command does:

  • gcc calls the compiler
  • hello.c is the source file
  • -o hello tells GCC to name the output executable hello instead of the default a.out

Run the Compiled Binary

./hello

Expected output:

Hello from Rocky Linux 10!

If you see that output, your GCC installation is fully functional. The compiler preprocessed, compiled, assembled, and linked the source code into a working executable in a single command.

Test C++ Compilation

nano hello.cpp
#include <iostream>
int main() {
    std::cout << "C++ works on Rocky Linux 10!" << std::endl;
    return 0;
}
g++ hello.cpp -o hello_cpp
./hello_cpp

Expected output:

C++ works on Rocky Linux 10!

Understanding What GCC Does Behind the Scenes

When you run gcc hello.c -o hello, GCC moves through four internal stages:

  1. Preprocessing — expands #include directives and macros, strips comments
  2. Compilation — checks syntax and semantics, applies optimizations, converts to architecture-specific assembly
  3. Assembly — turns assembly code into binary object files (.o files)
  4. Linking — joins object files with system libraries like libc to produce the final executable

Understanding these stages helps when you start using flags like -Wall (enable all warnings), -O2 (enable level 2 optimization), -g (include debug symbols for GDB), or -std=c17 and -std=c++20 to target a specific language standard.

Troubleshooting Common GCC Installation Errors on Rocky Linux 10

Even a straightforward Linux server tutorial like this one can hit snags depending on how the system is configured. Here are the five most common errors and exactly how to fix them.

Error 1: “No package gcc available” or “No match for argument: gcc”

Cause: The AppStream or BaseOS repository is disabled or the package metadata is stale.

Fix:

sudo dnf repolist
sudo dnf clean all
sudo dnf update -y
sudo dnf install gcc -y

Run dnf repolist first to confirm that appstream and baseos both appear as enabled. If they show as disabled, re-enable them:

sudo dnf config-manager --set-enabled appstream baseos

Error 2: Dependency Conflicts During Install

Cause: Partially updated packages or conflicting RPM metadata.

Fix:

sudo dnf clean all
sudo dnf distro-sync -y
sudo dnf install gcc -y

distro-sync aligns all installed packages to the versions in the current repository, which resolves most dependency conflicts.

Error 3: “command not found: scl”

Cause: The scl-utils package is not installed, which is required to use GCC Toolsets.

Fix:

sudo dnf install scl-utils -y

After installation, retry your scl enable gcc-toolset-13 bash command.

Error 4: Wrong GCC Version Active After Toolset Install

Cause: You installed a GCC Toolset but did not start a new shell session with scl enable, so the system default GCC is still active.

Fix:

scl enable gcc-toolset-13 bash
gcc --version

The version should now reflect the toolset. If you want this to persist, add source scl_source enable gcc-toolset-13 to your .bashrc as shown in Step 5.

Error 5: “Permission denied” When Running DNF

Cause: The command was run without sudo by a non-root user.

Fix: Prepend sudo to all dnf install commands. Rocky Linux enforces strict privilege separation for package management.

sudo dnf install gcc -y

If your user account does not have sudo access, ask your system administrator to add you to the wheel group:

sudo usermod -aG wheel your_username

Log out and back in for the change to take effect.

Congratulations! You have successfully installed GCC. Thanks for using this tutorial for installing GCC (GNU Compiler Collection) on your Rocky Linux 10 system. For additional help or useful information, we recommend you check the official GCC website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a dedicated and highly skilled Linux Systems Administrator with over a decade of progressive experience in designing, deploying, and maintaining enterprise-grade Linux infrastructure. His professional journey began in the telecommunications industry, where early exposure to Unix-based operating systems ignited a deep and enduring passion for open-source technologies and server administration.​ Throughout his career, r00t has demonstrated exceptional proficiency in managing large-scale Linux environments, overseeing more than 300 servers across development, staging, and production platforms while consistently achieving 99.9% system uptime. He holds advanced competencies in Red Hat Enterprise Linux (RHEL), Debian, and Ubuntu distributions, complemented by hands-on expertise in automation tools such as Ansible, Terraform, Bash scripting, and Python.
Back to top button