Easy Steps to Install GCC(C and C++ Compiler) on CentOS 7


In this article I will take you through the steps to install GCC on CentOS 7. As per GCC Document ,The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Ada, Go, and D, as well as libraries for these languages (libstdc++,...). GCC was originally written as the compiler for the GNU operating system. The GNU system was developed to be 100% free software, free in the sense that it respects the user's freedom.

Easy Steps to Install GCC(C and C++ Compiler) on CentOS 7 1

Install GCC On CentOS 7

Also Read: How to install PHP on Ubuntu 18.04


Step 1: Prerequisites

a)You need to have a running CentOS 7 System.
b)Also you need to have wget installed in your system with internet connection.
c)Lastly you need to login with root access or user with sudo access to run gcc installation commands. In this tutorial, I am using root access.

Step 2: Update Your System

Firstly you need to update your system using yum update command. This command will update all the currently installed packages in your system to the latest available version.

[root@localhost ~]# yum update
Loaded plugins: fastestmirror
Determining fastest mirrors
* base:
* extras:
* updates:
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00

Step 3: Download and Install GCC from Repository

Download from Repository and install gcc tool using yum install gcc command.

[root@localhost ~]# yum install gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base:
* extras:
* updates:
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-39.el7 will be installed
--> Processing Dependency: cpp = 4.8.5-39.el7 for package: gcc-4.8.5-39.el7.x86_64


Step 4: Install from Source Code.

There is another method that you can use to install gcc tool in your system, that is through source code which is also the recommended way to install.


Download Source Code

Download GCC Source File from GNU FTP Site using wget. It will download gcc package in local directory.

[root@localhost ~]# wget
--2019-12-31 04:47:37--
Resolving (, 2001:470:142:3::b
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 124304709 (119M) [application/x-gzip]
Saving to: ‘gcc-9.2.0.tar.gz’

100%[==============================================================================================================================>] 124,304,709 2.83MB/s in 49s

2019-12-31 04:48:27 (2.43 MB/s) - ‘gcc-9.2.0.tar.gz’ saved [124304709/124304709]

Extract the Files

Once downloaded, you need to extract the gcc package by using tar -xvf gcc-9.2.0.tar.gz command.

[root@localhost ~]# tar -xvf gcc-9.2.0.tar.gz

Build the Configuration

Once extracted go to gcc-9.2.0 directory by doing cd gcc-9.2.0 and run ./configure.

[root@localhost ~]#cd gcc-9.2.0
[root@localhost ~]#./configure

Compile the Source Code

Once configuration completed successfully, now it is time to compile the source code by running make command.

[root@localhost ~]#make

Install GCC Using make 

Once all the source code are compiled, it is now time to install them using make install command.

[root@localhost ~]#make install


As per make man page, The purpose of the make utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them. The manual describes the GNU implementation of make, which was written by Richard Stallman and Roland McGrath, and is currently maintained by Paul Smith. Our examples show C programs, since they are most common, but you can use make with any programming language whose compiler can be run with a shell command. In fact, make is not limited to programs. You can use it to describe any task where some files must be updated automatically from others whenever the others change.

Step 5: Check GCC Version

Once GCC is installed in your system, you can check the gcc version by using gcc --version command.

[root@localhost ~]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

Step 6: Write Your first C Program

Since that we have installed GCC Compiler now, let's write our First "Hello World" C Program.

[root@localhost ~]# cat hello.c
#include <stdio.h>
void main()
printf("Hello World\n");

Let's Compile this Program.

[root@localhost ~]# gcc -o hello hello.c

Check the Output. It shows Hello World in the output.

[root@localhost ~]# ./hello
Hello World

Also Read: How to create a Filesystem on Linux Partition


Popular Searches

  • centos install gcc
  • gcc linux
  • what is gcc
  • gcc download
  • gcc latest version

Leave a Comment