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.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.

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.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Ravi Saive
I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

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

2 Comments

Leave a Reply

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.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.