How to Run C Program in Ubuntu 24.04 LTS Linux

How to Run C Program in Ubuntu 24.04 LTS Linux | Step-by-Step Guide

Learning how to run a C program on Ubuntu 24.04 LTS Linux can be a valuable skill for developers and computer science students. This guide will walk you through the process of setting up your development environment, writing a simple C program, compiling it, and running it on Ubuntu 24.04 LTS. Follow these steps to get started with C programming on your Linux system.

**Step-by-Step Instructions:**

**Step 1: Open Terminal**
1. Press `Ctrl + Alt + T` or search for “Terminal” in the Applications menu to open a terminal window.

**Step 2: Install GCC Compiler**
1. The GCC (GNU Compiler Collection) is a powerful compiler for C (and other languages). To install GCC, run the following commands:
sudo apt update
sudo apt install build-essential
2. Verify the installation by checking the GCC version:
gcc –version
3. You should see output indicating the version of GCC installed.

**Step 3: Write Your C Program**
1. Use a text editor to create a C program. You can use editors like `nano`, `vim`, or graphical editors like `Gedit` or `VS Code`. For simplicity, let’s use `nano`:
nano hello.c
2. In the editor, write a simple C program. For example:
// hello.c
#include stdio.h

int main() {
printf(“Hello, Ubuntu 24.04 LTS!n”);
return 0;
3. Save and exit the editor. In `nano`, you can do this by pressing `Ctrl + X`, then `Y` to confirm, and `Enter` to save.

**Step 4: Compile the C Program**
1. To compile your C program, use the GCC compiler:
gcc hello.c -o hello
2. This command compiles `hello.c` and creates an executable file named `hello`. The `-o` option specifies the name of the output file.

**Step 5: Run the Compiled Program**
1. To run the compiled program, use the following command:
2. You should see the output:
Hello, Ubuntu 24.04 LTS!

**Additional Tips:**
– **Debugging**: Use `gdb`, the GNU Debugger, for debugging your C programs. Install it with:
sudo apt install gdb
Run your program with gdb:
gdb ./hello
– **IDE Support**: Consider using an Integrated Development Environment (IDE) like CLion, Code::Blocks, or Visual Studio Code with C/C++ extensions for a more comprehensive development experience.
– **Makefiles**: For larger projects, consider using Makefiles to manage the build process. Create a file named `Makefile` with appropriate build rules.

By following these steps, you can easily write, compile, and run C programs on your Ubuntu 24.04 LTS system. Happy coding!

Don’t forget to like, share, and subscribe for more programming tutorials and tips!

#CProgramming #Ubuntu #Linux #Coding #Programming #TechTutorial #HowTo #GCCCompiler #OpenSource #Ubuntu2404LTS #TechTips #Tutorial