You need to compile your program before you can run it. To do this, you'll need a C compiler, like gcc. You can install this with:

sudo apt-get install gcc

Then, to compile your program, creating an executable called file:

gcc -Wall -o file file.c

Which you should then be able to run:

./file
Answer from Jeremy Kerr on askubuntu.com
🌐
GeeksforGeeks
geeksforgeeks.org › techtips › how-to-run-c-program-in-ubuntu
How to Run C program in Ubuntu - GeeksforGeeks
March 6, 2026 - To compile and run a C program in Ubuntu, you need the GCC compiler, which is included in the build-essential package. After installing it, you can create, compile, and execute C programs directly from the terminal.
🌐
It's FOSS
itsfoss.com › run-c-program-linux
How to Run C Program in Ubuntu Linux [Terminal & GUI Ways]
March 29, 2023 - Step 1: Write your program and save the file with a .c extension. For example, my_program.c. Step 2: You compile the program and generate the object file using gcc compiler in a terminal like this:
🌐
Scaler
scaler.com › home › topics › how to run c program in ubuntu
How to Run C Program in Ubuntu? | Scaler Topics
May 4, 2023 - Next, we ran the gcc prime.c -o prime command to compile the prime.c program and finally we ran the ./prime command to get the output on the terminal screen. To get a basic to advanced understanding of the C programming language, learn from the Scaler Topics curated C Programming Tutorial. Learn more about C Online Compiler in C programming language. Ubuntu is a widely used Linux-based operating system for running Linux-based programs.
🌐
YouTube
youtube.com › watch
How To Run C Programs In The Linux (Ubuntu) Terminal - YouTube
How to run C programs in the terminal of your Linux machine.
Published   August 28, 2021
🌐
VITUX
vitux.com › how-to-write-and-run-a-c-program-in-linux
How to Write and Run a C Program in Linux – VITUX
April 20, 2023 - To open the terminal, you can use the Ubuntu Dash or the key combination Ctrl+Alt+T. In order to compile and execute a C program, you need to have the essential packages installed on your system. Enter the following command as root in your Linux Terminal:
🌐
Ruc
akira.ruc.dk › ~keld › teaching › CAN_e14 › Readings › How to Compile and Run a C Program on Ubuntu Linux.pdf pdf
1 How to Compile and Run a C Program on Ubuntu Linux Keld Helsgaun
Launcher). Open up a terminal by clicking on the icon. ... Step 2. Use a text editor to create the C source code. ... Close the editor window. ... Step 3. Compile the program.
🌐
San Diego State University
ost.sdsu.edu › osticket › kb › faq.php
Run a C Program in Linux
Run a C Program in Linux · Last Updated 4 years ago · Let us write a simple C program. Open Ubuntu’s graphical Text Editor and write or copy the following sample program into it: #include int main() { printf("\nA sample C program\n\n"); return 0; } Then save the file with .c extension. In this example, I am naming my C program as sampleProgram.c · Alternatively, you can write the C program through the Terminal in gedit as follows: $ vi sampleProgram.c ·
Find elsewhere
🌐
Medium
wiredgorilla.medium.com › how-to-write-compile-and-run-a-c-program-in-ubuntu-and-other-linux-distributions-beginners-tip-807987bfc293
How to Write, Compile and Run a C Program in Ubuntu and Other Linux Distributions [Beginner’s Tip] | by Wired Gorilla | Medium
November 21, 2020 - How do you program in C on Linux? It is indeed very easy and consists of three simple steps. Step 1: You write your program and save the file with a .c extension. For example, my_program.c. Step 2: You compile the program and generate the object ...
🌐
Learn Ubuntu
learnubuntu.com › run-c-programs
Running C Programs in Ubuntu Command Line
April 4, 2023 - The GCC compiler used to compile C-programs into executable files is available in the official repositories of apt. Installing gcc in Ubuntu is fairly simple. ... Optional: If you want to install an array of all the C and C++ related tools, you can install the clang package rather than gcc alone. It includes all other compiling tools too. Once you are ready with the compiler, you can write programs and compile and execute them.
🌐
San Diego State University
ost.sdsu.edu › kb › faq.php
Engineering Help Desk
Run a C Program in Linux · Last Updated 4 years ago · Let us write a simple C program. Open Ubuntu’s graphical Text Editor and write or copy the following sample program into it: #include int main() { printf("\nA sample C program\n\n"); return 0; } Then save the file with .c extension. In this example, I am naming my C program as sampleProgram.c · Alternatively, you can write the C program through the Terminal in gedit as follows: $ vi sampleProgram.c ·
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › how to compile a c program in linux
How to Compile and Run a C Program in Linux Terminal
August 29, 2025 - You can open it using Ctrl + Alt + T on Ubuntu or search for "Terminal" in the applications menu. GCC (GNU Compiler Collection) – GCC is the most widely used compiler for C programs.
🌐
Osnote
osnote.com › how-to-write-and-run-a-c-program-on-ubuntu
How to Write and Run a C Program on Ubuntu - <OSNote>
March 21, 2022 - In this guide, you will learn how to write your first C program using the Linux operating system which requires just the GNU C compiler and a text editor and not a full blown integrated development environment to get started.
🌐
Slideshare
slideshare.net › home › engineering › how to compile and run a c program on ubuntu linux
How to compile and run a c program on ubuntu linux | DOC
This document shows how to compile and run a C program on Ubuntu Linux in 3 steps: 1. Open a terminal and use a text editor to create a C source code file called hello.c containing a simple "Hello World" program.
🌐
UbuntuMint
ubuntumint.com › home › shell tips › how to compile and run c/c++ program in ubuntu
How to Run C and C++ Program in Ubuntu Linux
December 4, 2023 - To run and compile the C program properly in your Ubuntu system, you need to install the build-essential package, which includes GCC/g++ compilers and libraries which are required to compile and run C programs in Linux.
🌐
LinuxWays
linuxways.net › ubuntu › how-to-run-a-c-program-in-ubuntu-linux
How to Run a C Program in Ubuntu Linux? – LinuxWays
To run a C Program in Ubuntu, you need to install the “gcc” compiler as it is not pre-installed in Ubuntu. Once you add the “gcc” Compiler, you can use either the Terminal to run the C Program or you can download any code editor and run the C Program through the Ubuntu GUI.
🌐
LinuxWays
linuxways.net › ubuntu › how-to-create-and-run-a-c-program-using-ubuntu-20-04-lts
How to create and run a C program using Ubuntu 20.04 LTS – LinuxWays
July 10, 2021 - This icon can be found at the bottom right of the launcher bar as shown in the image below. This will take you to the Applications Menu, as shown below. Type terminal in the search bar.
🌐
Scaler
scaler.com › home › topics › how to compile c program in linux?
How to Compile C Program in Linux? - Scaler Topics
April 13, 2024 - Let's see this in action in Ubuntu 20.04 OS. Use gcc hello.c -o hello command to compile the hello.c program and generate a hello executable file. You can see in the below image that a hello file is created in the Desktop directory.