How to install GCC compiler on CentOS 7

The GNU Compiler Collection (GCC) is a collection of compilers, including C, C++, Objective-C, Fortran, Ada, Go, and D languages. Many open source projects including GNU tools and Linux Kernel are compiled with GCC.

This guide explains how to install the GCC compiler on CentOS 7. We will explain how to install the stable version and install the updated version from the SCL source.

1. Prerequisites##

To add new software sources and install software packages on your CentOS system, you must log in to the system as root or a user with sudo privileges.

2. Install GCC on CentOS

The default CentOS software source contains a package group named Development Tools. This combination includes the GCC compiler and a series of library files, as well as other tools needed to compile the software.

To install Development Tools including the GCC compiler, run:

sudo yum group install "Development Tools"

This command installs a new set of packages, including gcc, g++, and make.

You may also want to install a user manual on developing with GNU/Linux:

sudo yum install man-pages

Use gcc -version to verify whether the GCC compiler is installed successfully, it will print the GCC version:

gcc --version

On the CentOS 7 software source, the default GCC available version is 4.8.5:

gcc(GCC)4.8.520150623(Red Hat 4.8.5-36)Copyright(C)2015 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.

That's it. GCC has been successfully installed on your system, and you can start using it.

Three, compile a Hello World example##

Compiling a C or C++ program with GCC is a very simple task. Open your text editor and create the following files:

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

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

gcc hello.c -o hello

This will create a binary file named hello in the same folder.

Execute this hello program:

. /hello

The program should output:

Hello World!

Fourth, install multiple versions of GCC

In this section, we will provide instructions on how to install and use multiple versions of GCC on CentOS 7. The updated version of GCC compiler includes support for new languages, better performance, and additional features.

Software Collections, as we know it, SCL is a community project that allows you to compile, install, and use multiple versions of software on the same system. By enabling software collections, you can install newer versions of programming languages and services that are not on the core software source.

The SCL software source provides a package called Developer Toolset, which contains an updated version of the GNU Compiler Collection, as well as other development and debugging tools.

First, install the CentOS SCL file. It is part of the CentOS additional source, you can install it with the following command:

sudo yum install centos-release-scl

Now, the following collection of development tools are available:

In this example, we install Developer Toolset 7. To do this, enter the following command in your CentOS terminal

sudo yum install devtoolset-7

To access GCC 7, you need to use the software collection tool scl to start a new shell:

scl enable devtoolset-7 bash

Now, if you check your GCC version, you can notice that GCC7 is already the default version of your current shell:

gcc --version
gcc(GCC)7.3.120180303(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 new version of GCC, just like other tools.

Five, summary##

You have successfully installed GCC on your CentOS 7. Now you can browse Official GCC Documentation Page, and learn how to use GCC and G++ to compile your C and C++ programs.

Recommended Posts

How to install GCC compiler on CentOS 7
How to install GCC compiler on Ubuntu 18.04
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
How to install Memcached on CentOS 8
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
How to install Yarn on CentOS 8
How to install Nginx on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to install MariaDB on CentOS 8
How to install MongoDB on CentOS 7
How to install Odoo 13 on CentOS 8
How to install Apache on CentOS 8
How to install OpenCV on CentOS 8
How to install PHP on CentOS 8
How to install MongoDB on CentOS 8
How to install Apache Maven on CentOS 8
How to install Apache Kafka on CentOS 7
[Graphic] How to install tomcat on centos
R&amp;D: How To Install Python 3 on CentOS 7
How to install offline JDK1.8 on centos7.0
How to install and configure Elasticsearch on CentOS 7
How to install Visual Studio Code on CentOS 8
How to install RPM packages on CentOS Linux
How to install and configure VNC on CentOS 8
How to install and configure Redis on CentOS 8
How to install Node.js and npm on CentOS 8
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and configure phpMyAdmin on CentOS 6
How to install and use Curl on CentOS 8
How to install and configure Owncloud on CentOS 8
How to install VirtualBox client extension on CentOS 8
How to install Docker CE on RHEL 8 / CentOS 8
How to install and uninstall tomcat on centos
How to install gcc compiler faster under Ubuntu
How to install and configure Redmine on CentOS 8