Want to step into the programming world and confused about selecting your first programming language? If yes, No worries! We are here for your assistance.

For new learners, the C Programming language is proven as the most popular and easy-to-use programming language. Its simple syntax can assist in understanding the architecture of a computer. Moreover, after mastering the C Programming Language, you can employ its logical concepts in other programming languages.

This write-up will discuss the procedure for using the C Programming Language on Ubuntu 22.04. So, let’s start!

How to install C Programming Language on Ubuntu 22.04

Before jumping right into the usage of C Programming Language, you are required to install it first on your Ubuntu 22.04 system.

To use the C Programming Language, it is required to install the “build-essential” package. It is also known as a “meta-package” that comprises everything needed for the compilation of the application based on C or C programming language.

Here is the procedure for installing the C Programming Language on Ubuntu 22.04:

Step 1: Update system repositories


Press “CTRL ALT T” to open the terminal of Ubuntu 22.04 and run the below-given commands to update system repositories:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-To-Use-the-C-Programming-Language-in-Ubuntu-22.04-1.png" data-lazy- height="390" src="data:image/svg xml,” width=”838″>

Step 2: Install build-essential package


After updating the system repositories, execute the following command for the installation of the “build-essential” package:

$ sudo apt install build-essential

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-To-Use-the-C-Programming-Language-in-Ubuntu-22.04-2.png" data-lazy- height="574" src="data:image/svg xml,” width=”818″>

The error-free output indicates that the “build-essential” package successfully installed the collection of libraries and compiler for the C Programming Language:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-To-Use-the-C-Programming-Language-in-Ubuntu-22.04-3.png" data-lazy- height="574" src="data:image/svg xml,” width=”820″>

Step 3: Check the C Compiler version


To check the version of the installed C Compiler on your Ubuntu 22.04, utilize the “gcc” command with the “–version” option:

As you can see from the output, GCC version “11.2.0” now exists on our system:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-To-Use-the-C-Programming-Language-in-Ubuntu-22.04-4.png" data-lazy- height="291" src="data:image/svg xml,” width=”819″>

Now, we will move ahead towards the usage of the C Programming Language on Ubuntu 22.04.

How to use the C Programming Language on Ubuntu 22.04

After the successful installation of the C language compiler, open up your favorite text editor and write out the following simple C program in it:

#include


int main() {    

    int n1, n2, sum;


    printf(“Kindly, Enter two integers: “);


    scanf(“%d %d”, &n1, &n2);


    sum = n1 n2;      


    printf(“%d %d = %d”, n1, n2, sum);


    return 0;

}

After adding the code, click on the “Save” button and save this opened file as “testfile.c”:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-To-Use-the-C-Programming-Language-in-Ubuntu-22.04-5.png" data-lazy- height="351" src="data:image/svg xml,” width=”674″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-To-Use-the-C-Programming-Language-in-Ubuntu-22.04-6.png" data-lazy- height="489" src="data:image/svg xml,” width=”877″>

Your “testfile.c” will somehow look like this:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-To-Use-the-C-Programming-Language-in-Ubuntu-22.04-7.png" data-lazy- height="331" src="data:image/svg xml,” width=”666″>

In the next step, we will compile “testfile.c” with the help of the GCC compiler:

$ gcc -o testfile testfile.c

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-To-Use-the-C-Programming-Language-in-Ubuntu-22.04-8.png" data-lazy- height="233" src="data:image/svg xml,” width=”816″>

To check the output of your C program, run the executable “testfile” and input two numbers:

For instance, we will enter “1” and “2” numbers, and our “testfile” C program will print out their sum on the terminal window:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/05/echo/How-To-Use-the-C-Programming-Language-in-Ubuntu-22.04-9.png" data-lazy- height="260" src="data:image/svg xml,” width=”812″>

We have compiled the most basic method to install and use the C Programming Language on Ubuntu 22.04.

Conclusion

To use the C Programming Language on Ubuntu 22.04, first, update the system repositories and run the “$ sudo apt install build-essential” command. The “build-essential” package will install all of the required libraries and compilers related to the C Programming language. You can then use it to write and execute C programs with the “GCC” compiler. This write-up discussed the method of using the C Programming Language in Ubuntu 22.04.

About the author

<img alt="" data-lazy-src="https://secure.gravatar.com/avatar/c73b74cd8044d2e9b300610f5af77d0b?s=112&r=g" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.