How to write and run a C language program on Linux?
To write and run C language programs, you need to install a C compiler first. On Linux, a commonly used C compiler is GCC (GNU Compiler Collection). Here are the steps for writing and running C language programs on Linux:
- Open the terminal.
- Update the system with the command “sudo apt update” and install necessary build tools with “sudo apt install build-essential”.
- file named hello.c
- edit the file hello.c using nano
- #include
int main() {
printf(“Greetings, Earth!\n”);
return 0;
} - Save and close the file.
- Compile the hello.c file using GCC and generate an executable named hello.
- greetings
- execute the hello program
- Greetings, Earth!
Please note that the steps above are performed on Ubuntu or Debian-based Linux distributions. For other Linux distributions, you may need to use a different package manager to install the GCC compiler.