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.
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.
Note: For linux distributions other than Ubuntu/Debian and Fedora, please refer to the official documentation of your distribution.
Not sure which Linux you’re using? Open Terminal and run this command:
cat /etc/os-release
Look for the ID
line:
ubuntu
or debian
→ Follow the Ubuntu/Debian instructions belowfedora
→ Follow the Fedora instructions belowHow to open Terminal:
Ctrl + Alt + T
(shortcut)sudo apt update
sudo apt install build-essential
gcc
(C compiler), g++
(C++ compiler), and essential build toolssudo dnf update
y
and press Enter when promptedsudo dnf groupinstall "Development Tools"
gcc
, g++
, and essential development toolsy
when asked to confirm and wait for installation to completeLet’s make sure everything is working properly!
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.
g++ --version
You should see similar version information.
Problem: “gcc is not recognized” or “command not found”
This means the compiler wasn’t installed properly. Here’s how to fix it:
sudo apt update
sudo apt install gcc g++ build-essential
sudo dnf install gcc gcc-c++
Problem: “Permission denied” errors
sudo
before commandsProblem: “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
Here’s what you just accomplished:
Now that you have a working C/C++ compiler:
gcc
and g++
Your Linux system is now ready for C/C++ programming!
Troubleshooting Tips:
man gcc
to read the compiler documentationBack to: Home | Next: VSCode Setup |