Fedora is a modern Linux distribution that provides a stable and powerful environment for development using a tool called C compiler, which is used to compile C programs into executable files.
In Fedora, the C compiler tool is part of a package called gcc (GNU Compiler Collection), and this article will guide you through the steps to install gcc and get started with compiling C programs on Fedora.
Installing GCC (C and C++ Compiler) on Fedora
Before installing any new software, it’s a good practice to update your existing system software packages to the latest available security updates.
sudo dnf update
Next, install gcc, which is a part of development tools that includes gcc and other essential tools like make, gdb, and git.
sudo dnf groupinstall "Development Tools"
After the installation is complete, you should verify that gcc is correctly installed and available on your system.
gcc --version
Writing a Simple C Program in Fedora
To test if gcc is working properly, you can write a simple C program by creating a hello.c
file.
nano hello.c OR vi hello.c
In the editor, write the following C program:
#include <stdio.h> int main() { printf("Hello, World!n"); return 0; }
Now that you have written a simple C program, you need to compile it using the gcc command to create an executable file named hello
.
gcc hello.c -o hello
Once the compilation is successful, you can run the executable file to see the output of your C program.
./hello
To learn more about how to use gcc, you can refer to the official GCC documentation or use the man command to view the manual page:
man gcc
For more advanced C programming, you might need additional libraries and tools based on the requirements of your development projects.
sudo dnf install glibc-devel [GNU C Library] sudo dnf install libm [Math Library] sudo dnf install gdb [Debugging Tool]
Uninstalling GCC (C and C++ Compiler) on Fedora
If you ever need to remove gcc from your system, you can uninstall it using the following command:
sudo dnf remove gcc
If you installed the entire “Development Tools” group and want to remove it, you can use:
sudo dnf groupremove "Development Tools"
Conclusion
You have now successfully installed the C compiler with needed development tools on Fedora and learned how to compile and run a simple C program.