How to install GCC the C compiler on Ubuntu 20.04 LTS Focal Fossa Linux

GCC, the GNU Compiler Collection is a compiler system developed to support various programming languages. It is a standard compiler used in most projects related to GNU and Linux, for example, Linux kernel. The objective of this tutorial is to install GCC the C compiler on Ubuntu 20.04 LTS Focal Fossa Linux. This will be achieved by using the apt install command.

In this tutorial you will learn:

  • How to install GCC compiler
  • How to Check C compiler version
  • How to Compile basic C program from source code
  • How to run C program

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or upgraded Ubuntu 20.04 Focal Fossa
Software GCC
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Install GCC the C compiler on Ubuntu 20.04 step by step instructions

Although you can install the C compiler separately by installation of the gcc package, the recommended way to install the C compiler on Ubuntu 20.04 is by installation of the entire development package build-essential.

  1. Install C compiler by installation of the development package build-essential:
    $ sudo apt install build-essential
    
  2. DO YOU NEED MULTIPLE C AND/OR C++ COMPILER VERSIONS?
    Visit “How to switch between multiple GCC and G++ compiler versions on Ubuntu 20.04” to see how to install multiple compiler versions on the same Ubuntu system.
  3. Check C compiler version:
    $ gcc --version
    gcc (Ubuntu 9.2.1-17ubuntu1) 9.2.1 20191102
    


  4. Create a basic C code source. For example let’s create hello world C program. Save the following code as hello.c text file:
    #include <stdio.h>
    int main()
    {
       printf("Hello, World!");
       return 0;
    }
    
  5. Compile and execute the hello.c C code:
    $ gcc -o hello hello.c 
    $ ./hello 
    Hello, World!