billysoftacademy.com

Learn how to Install GCC (C and C++ Compiler) on Fedora

Introduction

Fedora is a modern Linux distribution that offers a stable and powerful environment for software development. It comes with a tool called a 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). In this tutorial we will walk you through the steps to install gcc and help you get started with compiling C programs on Fedora.

Requirements

The following is a list of items needed to complete the setup successfully:
1) Fedora Server or Workstation 32 or any newer version.
2) An SSH client such as Putty or the macOS terminal app.
3) A static private or public IP address.
4) A domain name pointing to the Fedora IP address.
5) A stable internet connection

Overview

The following is a list of items needed to complete this setup successfully:
1) Open an SSH connection to the Fedora server
2) Download and install GCC
3) Write a simple C program
4) Compile and run the program using GCC
5) TIP: Uninstalling GCC
6) Conclusion and next steps

Step 1: Open an SSH connection to the Fedora server

To establish an SSH connection to a Fedora server, follow these steps.

Using macOS Terminal:
1. Open the Terminal application from your Applications folder.
2. Enter the following command, replacing “username,” “server_ip,” and “port_number” with the correct information:

ssh username@server_ip -p port_number

3. Press Enter and enter your password when prompted. If you’ve set up SSH key-based authentication, you won’t be asked for a password. To use a different port than the default SSH port (22), use the -p option when entering the command.

Using PuTTY for Windows:

1. Download and install PuTTY from https://www.putty.org/.
2. Launch the PuTTY application.
3. In the Session category, enter the hostname or IP address of your Fedora server in the Host Name field. If using a non-standard port, enter it in the Port field.
4. Click the Open button and enter your username and password when prompted.

Using SSH keys is more secure than password-based authentication. You can create secure tunnels for other network protocols using SSH.

Step 2: Download and install GCC

To install the GCC (C and C++ Compiler) on Fedora, it’s important to ensure that your system software packages are up to date with the latest security updates. You can do this by running the following command:
sudo dnf update
Once your system is updated, proceed to install the development tools, which include GCC along with other essential tools like make, gdb, and git. Use the following command:
sudo dnf groupinstall "Development Tools"
After the installation is complete, you can verify that GCC is correctly installed by checking its version with the following command:
gcc --version

Step 3: Write a simple C program

Now that GCC and other important development tools are installed, you can test this installation by writing and running a simple C program. Create a new file named helloworld.c using the command:

nano helloworld.c

Add the following code to the file:

#include 
int main() {
    printf("Hello, World!\n");
    return 0;
}

Press control + O on your keyboard, press enter to confirm the changes made to the file and press control + x to exit the file.

Step 4: Compile and run the program using GCC

The next step is compiling and running the helloworld program that you creating in Step 3 Run the following command to start the compilation process:
gcc helloworld.c -o hello
When the compilation process completes, execute the following command to run the program:
./hello
You should see the following output in the terminal:
Hello, World!
You can also learn more about GCC by checking the official online documentation or using the man command:
man gcc
To do more complicated C programming you may need to install some additional libraries and tools. For example:
sudo dnf install glibc-devel   [GNU C Library]
sudo dnf install libm          [Math Library]
sudo dnf install gdb           [Debugging Tool]

Tip: Uninstalling GCC

If for some reason you would like to uninstall GCC, you can do so in a few simple steps. Run the folloiwng command to start the uninstallation process:
sudo dnf remove gcc
If you also installed the development tools, run the following command as well:
sudo dnf groupremove "Development Tools"

Conclusion and next steps

By following these steps, you’ve successfully installed GCC (C and C++ compiler) on your Fedora system. You’ve also written, compiled, and executed a simple C program to verify the installation. This provides a strong foundation for further C and C++ development on Fedora. Here are some next steps to consider:

1. Explore more complex C programming concepts and practice writing various types of programs.
2. Learn about additional libraries and tools available for C development in Fedora.
3. Install the necessary packages for C++ development using sudo dnf install gcc-c++.
4. Explore C++ syntax and features to expand your programming skillset.
5. Consider using an Integrated Development Environment (IDE) for C/C++ development. Popular options include Code::Blocks, CLion, and Visual Studio Code with extensions. These IDEs offer features like code completion, debugging tools, and project management to streamline your development process.

Remember, practice is key to mastering C and C++. Keep exploring, writing code, and learning new techniques to become a proficient programmer.
Scroll to Top