Where is My Linux GNU C or GCC Compilers Are Installed?

Where is my GNU C compiler? Where does the GNU C (gcc) compiler reside in the RHEL / Fedora / Debian / Ubuntu / CentOS Linux installation? How do I install GNU c/c++ compiler in Linux operating systems?

The GNU Compiler Collection (GCC) is a compiler system. It was created by the GNU Project supporting various programming languages such as C (gcc), C++ (g++), Objective-C, Objective-C++, Fortran (gfortran), Java (gcj), Ada (GNAT), and Go (gccgo).
Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements GNU gcc
Time 5m

You need to use the which command to locate c compiler binary called gcc. Usually, it is installed in /usr/bin directory.

Syntax

Open a terminal and then type the following which command to see Linux C Compiler location:
$ which g++
$ which cc
$ which gcc

Sample outputs:

/usr/bin/gcc

Another option is to use the type command as follows:
$ type -a gcc
$ type -a cc
$ type -a g++

OR use the command command as follows:
$ command -V gcc
$ command -V cc
$ command -V g++

Sample outputs:

Fig.01: Using various shell command to find out GNU compiler location

Display gcc version:

Type the following command
$ gcc -v
Sample outputs:

 Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)

Installing GNU compiler collection

You need to use the up2date command or yum command or apt-get command/apt command to install GNI C/C++ (gcc) and required libs as per your Linux distro.

Note: You must login as root using su - or sudo -s command and then use command as per your distro.

If you are using Red Hat Enterprise Linux version 4.0 or older, type the command:

# up2date gcc

If you are using CentOS/Fedora Linux or RHEL version 5.0 or above, type the command:

# yum group install "Development Tools"

If you are using Debian /Ubuntu Linux, type the command:

$ sudo apt-get install build-essential
OR
# apt-get install build-essential

Writing a sample test code

You can create a sample c code as follows:
$ vi foo.c
Append the following code:

/* my C program */
#include <stdio.h>
int main(void){
	char var_name[20];
	printf("May I know your name? ");
	scanf("%s", var_name);
	printf("Hello %s, let us be friends.\n", var_name);
	return 0;
}

Compile it as follows:
$ cc foo.c -o foo
$ ls -l foo
$ ./foo

Sample outputs:

May I know your name? Vivek
Hello Vivek, let us be friends.
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
30 comments… add one
  • sumit Oct 14, 2013 @ 10:28

    Hi,
    I found below error. Please help.

    [root@localhost objdir]# yum install gcc
    Loading “rhnplugin” plugin
    Loading “installonlyn” plugin
    This system is not registered with RHN.
    RHN support will be disabled.
    Setting up Install Process
    Setting up repositories
    No Repositories Available to Set Up
    Reading repository metadata in from local files
    Parsing package install arguments
    Setting up repositories
    No Repositories Available to Set Up
    Reading repository metadata in from local files
    No Match for argument: gcc
    Nothing to do

  • Swapnil Apr 29, 2014 @ 12:02

    yum install gcc is not working in rhel 6 server.

    Please help

  • nagesh Aug 11, 2014 @ 7:15

    Hi,
    I am using Kubuntu
    When I am giving command “# apt-get install gcc”
    It will give error like this,
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package gcc is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package ‘gcc’ has no installation candidate
    ———————————–
    Can you help me ?

  • Patrick Apr 23, 2016 @ 16:51

    Hi when I type in yum it says command not found. Help!!!

  • Ayushi Jun 8, 2016 @ 17:42

    I got exactly what i was looking for in this tutorial, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.