• Posted: 16-07-2025
  • Last Updated: 28-07-2025
  • Category: Server Guides

When managing a CentOS server, you often need to compile software from its source code, and g++ is an essential tool for this task. However, installing it can be confusing if you don't know the correct package name. This guide will show you how to install g++ correctly.

What is g++?

g++ is the compiler for the C++ programming language, part of the GNU Compiler Collection (GCC). It is a fundamental tool required to build and install many applications in a Linux environment.

Method 1: Install the "Development Tools" Group (Recommended)

This is the best and most recommended method because it installs the entire necessary development environment at once, including gcc, g++, make, git, and many other utilities. This approach helps prevent missing library errors in the future.

For CentOS 7 and older (using yum)

sudo yum groupinstall "Development Tools"

For CentOS Stream 8/9 and newer distributions (using dnf)

sudo dnf group install "Development Tools"

Method 2: Install Only the gcc-c++ Package

If you only need the g++ compiler and prefer not to install other tools, you can install the gcc-c++ package directly.

A Common Pitfall

New users often try the command yum install g++ and encounter an error.

No package g++ available.
Error: Nothing to do

The reason is that on Red Hat-based distributions (like CentOS, AlmaLinux), the package containing the g++ compiler is named gcc-c++.

The Correct Installation Command

  • For CentOS 7 and older (using yum):
    sudo yum install gcc-c++
  • For CentOS Stream 8/9 and newer distributions (using dnf):
    sudo dnf install gcc-c++

3. Verify the Installation

After completion, you can check the g++ version to confirm that the installation was successful.

g++ --version

A successful installation will return output similar to this:

g++ (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10)
Copyright (C) 2018 Free Software Foundation, Inc.

A Note on Compatibility Packages

Packages like compat-gcc-32 are typically only needed if you need to compile very old software that requires an older version of GCC. For most common use cases, you do not need to install them.

Share:
Rating:

( Total: 1 ratings. Average 5, scale: 1 to 5 )