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

September 8, 2019

Rate this post

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).

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


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

Sample outputs:


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
# 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.
This entry is 6 of 13 in the Linux GNU/GCC Compilers Tutorial series. Keep reading the rest of the series:

  1. Ubuntu Linux Install GNU GCC Compiler and Development Environment
  2. Debian Linux Install GNU GCC Compiler and Development Environment
  3. CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools
  4. Download and Install C, C++ Compiler on Red Hat Enterprise Linux 5 (RHEL)
  5. Mac OS X: Install GCC Compiler with Xcode
  6. Where is My Linux GNU C or GCC Compilers Are Installed?
  7. HowTo: Compile And Run a C/C++ Code In Linux
  8. RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers
  9. HowTo Compiling C Program And Creating Executable File Under a Linux / UNIX / *BSD
  10. How To Install ncurses Library on a Linux
  11. Linux Find Out What Compilers Are Installed or Available On The System
  12. Linux Find Out GNU gcc Compiler Version Used To Compile Running Kernel
  13. Howto see output of C program in Linux or UNIX

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.