How to Install GCC (C and C++ Compiler) on Fedora

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"
Install Development Tools in Fedora
Install Development Tools in Fedora

After the installation is complete, you should verify that gcc is correctly installed and available on your system.

gcc --version
Check GCC Vesrion
Check 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
Run C Program in Fedora
Run C Program in Fedora

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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.