Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Install GCC and build a Hello World application on RHEL 8

November 10, 2023
Nikhil Mungale
Related topics:
Developer ToolsLinux
Related products:
Developer ToolsRed Hat Enterprise Linux

Share:

    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

    • How to activate your no-cost Red Hat Enterprise Linux subscription

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

    Recent Posts

    • Staying ahead of artificial intelligence threats

    • Strengthen privacy and security with encrypted DNS in RHEL

    • How to enable Ansible Lightspeed intelligent assistant

    • Why some agentic AI developers are moving code from Python to Rust

    • Confidential VMs: The core of confidential containers

    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

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    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
    © 2025 Red Hat

    Red Hat legal and privacy links

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

    Report a website issue