[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedSeptember 7, 2023

How to Install GCC Compiler on CentOS 7.

How To Install GCC Compiler On CentOS 7.

This tutorial explains how to install the GCC compiler on CentOS 7. We’ll explain how to install the distro stable version and the newer version of GCC available from the SCL repository.

Installing GCC on CentOS

The default CentOS repositories contain a package group named Development Tools that contains the GCC compiler and a lot of libraries and other utilities required for compiling software.

To install the Development Tools including the GCC Compiler, run:

sudo yum group install "Development Tools"

The command installs a bunch of new packages including gcc, g++ and make.

You may also want to install the manual pages about using GNU/Linux for development:

sudo yum install man-pages

Validate that the GCC compiler is successfully installed by using the gcc –version command which prints the GCC version:

gcc --version

The default version of GCC available in the CentOS 7 repositories is 4.8.5:

gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
right (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for ing conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

That’s it. GCC is now installed on your system, and you can start using it.

Compiling a Hello World Example

Compiling a basic C or C++ program using GCC is an easy task. Open your text editor and create the following file:

nano hello.c
#include <stdio.h>
int main()
{
  printf ("Hello World!\n");
  return 0;
}

Save the file and compile it into an executable by running the following command:

gcc hello.c -o hello

This will create a binary file named hello in the same directory where you run the command.

Execute the hello program with:

./hello

The program should display:

Hello World!

Installing Multiple GCC Versions

In this section, we will provide instructions about how to install and use multiple versions of GCC on CentOS 7. The newer versions of the GCC compiler include support for new languages, better performance, extended features.

Software Collections , also known as SCL is a community project that allows you to build, install, and use multiple versions of software on the same system, without affecting system default packages. By enabling Software Collections, you gain access to the newer versions of programming languages and services which are not available in the core repositories.

The SCL repositories provide a package named Developer Toolset, which includes newer versions of the GNU Compiler Collection, and other development and debugging tools.

First, install the CentOS SCL release file. It is part of the CentOS extras repository and can be installed by running the following command:

sudo yum install centos-release-scl

Currently, the following Developer Toolset collections are available:

  • Developer Toolset 7

  • Developer Toolset 6

In this example, we’ll install the Developer Toolset version 7. To do so type the following command on your CentOS 7 terminal:

sudo yum install devtoolset-7

To access GCC version 7, you need to launch a new shell instance using the Software Collection scl tool:

scl enable devtoolset-7 bash

Now if you check the GCC version, you’ll notice that GCC 7 is the default version in your current shell:

gcc --version
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright (C) 2017 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.

At this point, you can use the newer GCC version just like any other regular tool.

Conclusion

You have successfully installed GCC on your CentOS 7. You can now visit the official GCC Documentation page and learn how to use GCC and G++ to compile your C and C++ programs.

Keep reading
How to Delete/Remove Users.
May 29, 2023

How to Delete/Remove Users.

How To Delete/Remove Users. This tutorial covers the userdel command and its options. Linux is a multi-user system, which means that more than one person can interact with the same system at the same time. As a system administrator, you have the responsibility to manage the system’s users and…

Read article
Bash Concatenate Strings
May 29, 2023

Bash Concatenate Strings

Bash Concatenate Strings In this tutorial, we will explain how to concatenate strings in Bash. One of the most commonly used string operations is concatenation. String concatenation is just a fancy programming word for joining strings together by appending one string to the end of another string.…

Read article
How to get CPU information.
May 29, 2023

How to get CPU information.

How To Get CPU Information. The CPU (central processing unit), often called simply processor, is one of the essential components of your computer. It performs all types of data processing operations, and it often referred to as the computer’s brain. Have you ever wondered what type of CPU you have…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00