How to run c program on linux/ubuntu


Because of its extensive library of functions, the C programming language is well-known among programmers. Linux does not allow the execution of C programs without a compiler. Therefore, to compile programming languages under Linux distribution, a specialized compiler is required. We will discover what C programming is in this article as well as how to compile C programs under Linux.

How to run the C program on Linux:

In order for a computer to be able to understand the C program code, a compiler must first translate the strings-based code into machine code. The GCC compiler, which is available in the default repository of the various Linux distributions and is simple to install using the apt package manager, is the most popular compiler used for C programming on Linux.

Sudo installation command

It is now time to create a file using the touch or cat commands with any name, for example, file1.c (the. c extension indicates to the computer that this file includes a C program).

The c file is created using the cat or touch command, cat > file1.c OR touch file1.c

File creation

Sample of c program for execution:


C Program sample

The program execution starts from the main() function of the program, print is used to print the output, and return 0 indicates that the program has successfully exited. We also included a header file called stdio, which is used to incorporate input and output-related information.

Once the c program file is created successfully, then the role of gcc is for compilation.


Role of gcc in linux

The compiler used in the aforementioned command is gcc, which compiles the file with the name file1.c, checks to see if there are any errors, and if there aren’t, generates the “file1” (binary file) in the same directory.


we can check the output through the ./file1 command.

How to check outpu on linux

Output is displayed on the above-shared image.

For Linux/ ubuntu basic commands visit the basic commands article.


Everyone wants to learn how to code in this age of information technology. In addition to being a recommended starting point for beginners, C programming is a general-purpose language. A c program can be used to construct applications at both an advanced level as well as to master the fundamentals of programming. we learned how to compile a C program in Linux using the GCC compiler. In addition to the terminal, Linux users can install alternative GUI (Graphical User Interface) based compilers like Visual Studio to compile and run C programs.


Related Articles

Leave a Reply

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

Back to top button