Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Install GCC and build a Hello World application on RHEL 8

November 10, 2023
Nikhil Mungale
Related topics:
Developer toolsLinux
Related products:
Developer ToolsetRed Hat Enterprise Linux

    In this tutorial, you will install the GNU Compiler Collection 12 from the Red Hat Developer Toolset and build a simple C++ Hello World application. This tutorial should take less than 30 minutes to complete.

    Prerequisites

    Before you begin, you will need a current Red Hat Enterprise Linux 8 workstation or server subscription that allows you to download software and get updates from Red Hat. If you don’t have an active subscription, you can register and obtain the Red Hat Enterprise Linux Developer Suite (including the RHEL server).

    Step 1. Discovering GCC-related repositories in RHEL 8

    Managing software repositories in Red Hat Enterprise Linux 8 is essential for developers and system administrators. To find the necessary GCC-related repositories, you can use the following command. This command helps you discover the repositories containing GCC-related tools, ensuring you have access to the latest and most up-to-date resources for your development needs. This is a valuable feature for simplifying repository management.

    Check the version of RHEL on the server:

    #  cat /etc/redhat-release
    Red Hat Enterprise Linux release 8.8 (Ootpa)

    List the GCC-related repositories using the following command:

    $ sudo dnf provides '*bin/gcc'

    Step 2. Set up your development environment

    In this step, you will use a single command to download and install GCC 12.x and other development tools that are part of the Red Hat Developer Toolset. The length of time this step takes depends on the speed of your Internet connection and system. With a reasonably fast connection, this step should take only a minute.

    Red Hat Enterprise Linux provides a comprehensive set of tools for developing C and C++ applications.

    1. Download and install the development tools package group, which includes GNU Compiler Collection (GCC), GNU Debugger (GDB), and other development tools:
    $ sudo dnf group install "Development Tools"
    1. Install the LLVM-based toolchain including the clang compiler and lldb debugger:
    $ sudo dnf install llvm-toolset
    1. If Fortran is needed, install the GNU Fortran compiler:
    $ sudo dnf install gcc-gfortran

    Step 3. Build a Hello World application

    Use DTS C++ from the command line

    The GNU C++ compiler runs with the gcc command. Add DTS to your environment with scl enable in a terminal window. You can also refer to Permanently adding DTS to your Development Environment for more information.

    $ scl enable gcc-toolset-12 bash

    1. Create a directory hello-cpp and change to it:

    $ mkdir hello-cpp
    $ cd hello-cpp

    2. Create a file hello.cpp with the following contents:

    hello.cpp

    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[]) {
      cout << "Hello, Red Hat Developer Program World!" << endl;
      return 0;
    }

    3. Now compile and run the program:

    $ gcc -o hello hello.cpp

    This will compile the code.

    4. Create the object the hello.cpp and link the executable hello file from the object file.

    $./hello
    Hello, Red Hat Developer Program World!

    For more information, read the GNU C++ Compiler section of the Red Hat GCC Toolset 12 User Guide.

    Docker-formatted container images

    You can use Docker-formatted container images to run Red Hat Developer Toolset components inside virtual software containers, thus isolating them from the host system and allowing rapid deployment. For a detailed description of the Developer Toolset docker-formatted container images and dockerfiles, refer to Using Red Hat Software Collections Container Images.

    Working with the GCC Toolset

    The GCC Toolset in Red Hat Enterprise Linux 8 remains supported, allowing developers to access cutting-edge development and performance analysis tools. This toolset is similar to the Red Hat Developer Toolset for RHEL 7 and is conveniently available as a software collection in the AppStream repository. Notably, it is fully supported under Red Hat Enterprise Linux Subscription Level Agreements, making it suitable even for production purposes.

    Developers using Red Hat Enterprise Linux 8 can leverage the GCC Toolset to benefit from more advanced and up-to-date tools that enhance efficiency and productivity. This includes a wide range of features such as improved optimizations, enhanced diagnostics, better performance analysis tools, and increased compatibility with modern programming languages.

    By providing a software collection within the AppStream repository, Red Hat ensures that developers have easy access to the GCC Toolset while maintaining consistent system stability and security standards. Moreover, its inclusion under Subscription Level Agreements reflects Red Hat's dedication to offering dependable products that meet enterprise requirements.

    Permanently adding DTS to your development environment

    To make DTS a permanent part of your development environment, you can add it to the login script for your specific user ID. This is the recommended approach for development because only processes run under your user ID will be affected.

    1. Using your preferred text editor, add the following line to the end of ~/.bashrc:

    $ source scl_source enable gcc-toolset-12

    2. After logging out and logging back in again, you can verify that the DTS GCC is in your path by running which gcc or gcc --version.

    $ which gcc
    /opt/rh/gcc-toolset-12/root/usr/bin/gcc
    ​​​​​​​$ gcc -v
    gcc (GCC) 12.2.1 20221121 (Red Hat 12.2.1-7)

    Troubleshooting and FAQ

    1. As a developer, how can I get a Red Hat Enterprise Linux subscription that includes the Clang/LLVM, Go, or Rust Compilers?

    Developers can get a no-cost Red Hat Enterprise Linux Developer subscription for development purposes by registering and downloading through developers.redhat.com. We recommend you follow our Getting Started Guide which covers downloading and installing Red Hat Enterprise Linux on a physical system or virtual machine (VM) using your choice of VirtualBox, VMware, Microsoft Hyper-V, or Linux KVM/Libvirt. For more information, see Frequently asked questions: no-cost Red Hat Enterprise Linux Developer subscription.

    2. When I run the dnf install package (gcc-toolset-12, llvm-toolset-9, rust-toolset-9), it fails due to a missing dependency.

    Packages from the devtools RPMs repository, which is not by default enabled, are needed by several software collections. For instructions on how to enable the relevant RPMs and repositories.

    3. How can I view the Go manual pages?

    The Go compiler help command provides information on its usage. To show the help index:

    $ man go

    4. How can I find out what RHSCL packages are installed?

    The scl list-collections will show the list of RHSCL packages that have been installed, whether they are enabled or not.

    $ scl list-collections

    Find more resources

    In this article, we installed GCC development tools on RHEL 8 and created a simple cpp application that printed hello-world and executed by the GCC command line tool.

    For a deeper and practical understanding of Red Hat Enterprise Linux, you can engage in thoughtfully curated hands-on labs. Red Hat Universal Base Images (UBI) are container-based and operating system images with complementary runtime languages and packages. Try the Red Hat UBI hands-on lab.

    You can also obtain tailored Red Hat Enterprise Linux images designed for AWS, Google Cloud Platform, Microsoft Azure, and VMware, facilitating their seamless deployment on your chosen platform.

    Related Posts

    • How to configure RHEL as a workstation during installation

    • Working with Red Hat Enterprise Linux Universal Base Images (UBI)

    • How to use Convert2RHEL to migrate CentOS to RHEL

    • Activate your no-cost Red Hat Enterprise Linux subscription

    • How to build a Quarkus app on RHEL using Microsoft SQL Server

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    What’s up next?

    Convert2RHEL is a command-line utility that can streamline your migration path from CentOS Linux 7 to a fully supported Red Hat Enterprise Linux (RHEL) operating system. This cheat sheet outlines how to convert your CentOS Linux instance to RHEL in just 7 steps.

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.