How to install GCC the C compiler on Ubuntu 22.04 LTS Jammy Jellyfish Linux

GCC (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, the Linux kernel. The objective of this tutorial is to install GCC, the C compiler, on Ubuntu 22.04 Jammy Jellyfish. Installation of GCC can be achieved by using the apt install command as you will see below.

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
How to install GCC the C compiler on Ubuntu 22.04 LTS Jammy Jellyfish Linux
How to install GCC the C compiler on Ubuntu 22.04 LTS Jammy Jellyfish Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 22.04 Jammy Jellyfish
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 22.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 22.04 Jammy Jellyfish is by installation of the entire development package build-essential.

  1. Open a command line terminal and install C compiler by installation of the development package build-essential:
    $ sudo apt update
    $ sudo apt install build-essential
    
    DO YOU NEED MULTIPLE C AND/OR C++ COMPILER VERSIONS?
    Visit our other tutorial on How to switch between multiple GCC and G++ compiler versions on Ubuntu 22.04 to see how to install multiple compiler versions on the same Ubuntu system.
  2. Check C compiler version to verify a successful installation:
    $ gcc --version
    
  3. We can verify that our GCC compiler works by creating a basic C code source. For example let’s create a hello world C program. Save the following code as hello.c text file:
    #include <stdio.h>
    int main()
    {
       printf("Hello, World!");
       return 0;
    }
  4. Compile and execute the hello.c C code:
    $ gcc -o hello hello.c 
    $ ./hello 
    Hello, World!
    
Using the GCC compiler on Ubuntu 22.04 Jammy Jellyfish Linux
Using the GCC compiler on Ubuntu 22.04 Jammy Jellyfish Linux

Closing Thoughts




In this tutorial, we saw how to install GCC, the very simple C compiler on Ubuntu 22.04 Jammy Jellyfish. We also learned how to create a simple Hello World C program in order to test the new compiler.