c-cpp-setup

C/C++ Setup on Linux

This guide will help you install everything you need to write and run C/C++ programs on Linux. I’ll cover both Ubuntu/Debian and Fedora systems.

What We’re Installing and Why

GCC (GNU Compiler Collection) = A free, powerful C/C++ compiler that’s the standard on Linux systems. Think of it as the tool that turns your C/C++ code into programs that can actually run on your computer.

Prerequisites (What You Need First)

Note: For linux distributions other than Ubuntu/Debian and Fedora, please refer to the official documentation of your distribution.

Step 1: Find Your Linux Distribution

Not sure which Linux you’re using? Open Terminal and run this command:

cat /etc/os-release

Look for the ID line:

How to open Terminal:

Step 2: Install GCC Compiler

For Ubuntu/Debian Systems:

  1. Update your system first:
    sudo apt update
    
    • Type your password when asked (you won’t see it as you type - this is normal!)
    • Press Enter and wait for it to finish
  2. Install the C/C++ compiler:
    sudo apt install build-essential
    
    • This installs gcc (C compiler), g++ (C++ compiler), and essential build tools
    • Wait for the installation to complete (usually 1-5 minutes)

For Fedora Systems:

  1. Update your system first:
    sudo dnf update
    
    • Enter your password when asked
    • Type y and press Enter when prompted
    • Wait for updates to complete
  2. Install the C/C++ compiler:
    sudo dnf groupinstall "Development Tools"
    
    • This installs gcc, g++, and essential development tools
    • Type y when asked to confirm and wait for installation to complete

Step 3: Test Your Installation

Let’s make sure everything is working properly!

  1. Test the C compiler:
    gcc --version
    

    You should see something like:

    gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
    Copyright (C) 2019 Free Software Foundation, Inc.
    
  2. Test the C++ compiler:
    g++ --version
    

    You should see similar version information.

  3. If both commands show version information, congratulations! Your setup is complete!

What if Something Goes Wrong?

Problem: “gcc is not recognized” or “command not found”

This means the compiler wasn’t installed properly. Here’s how to fix it:

  1. Make sure the installation completed successfully:
    • Re-run the installation command from Step 2
    • Watch for any error messages during installation
  2. For Ubuntu/Debian users:
    sudo apt update
    sudo apt install gcc g++ build-essential
    
  3. For Fedora users:
    sudo dnf install gcc gcc-c++
    

Problem: “Permission denied” errors

Problem: “Package not found” errors

For Ubuntu/Debian:

sudo apt update
sudo apt upgrade

Then try the installation commands again.

For Fedora:

sudo dnf clean all
sudo dnf update

Then try the installation commands again.

Problem: Installation is very slow

Quick Summary

Here’s what you just accomplished:

  1. Identified your Linux distribution
  2. Installed GCC (your C/C++ compiler)
  3. Tested that everything works

What’s Next?

Now that you have a working C/C++ compiler:

  1. Install VSCode - Follow the VSCode Setup Guide to get a nice editor
  2. Write your first program - Try creating more C/C++ programs
  3. Practice - Get comfortable with compiling programs using gcc and g++

Understanding What You Installed

Your Linux system is now ready for C/C++ programming!


Troubleshooting Tips:


Back to: Home Next: VSCode Setup