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:
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:
Validate that the GCC compiler is successfully installed by using the gcc –version command which prints the GCC version:
The default version of GCC available in the CentOS 7 repositories is 4.8.5:
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:
Save the file and compile it into an executable by running the following command:
This will create a binary file named hello in the same directory where you run the command.
Execute the hello program with:
The program should display:
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:
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:
To access GCC version 7, you need to launch a new shell instance using the Software Collection scl tool:
Now if you check the GCC version, you’ll notice that GCC 7 is the default version in your current shell:
At this point, you can use the newer GCC version just like any other regular tool.
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.