Learn how to Install GCC (C and C++ Compiler) on Fedora
Introduction
Requirements
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
sudo dnf updateOnce 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
gcc helloworld.c -o helloWhen the compilation process completes, execute the following command to run the program:
./helloYou 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 gccTo 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
sudo dnf remove gccIf you also installed the development tools, run the following command as well:
sudo dnf groupremove "Development Tools"
Conclusion and next steps
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.