Setting Up GCC and G++ Development Environment on Ubuntu

To compile C and C++ programs on Ubuntu, you need the GNU Compiler Collection (GCC). The most efficient way to install the necessary compilers, standard libraries, and build tools is by utilizing the build-essential meta-package.

Installation Process

Execute the following command in your terminal to fetch and install the required compiler suite:

sudo apt update && sudo apt install build-essential

Troubleshooting Repository Issues

If the installation fails due to dependency errors or broken package references, you're system may be configured with unstable or unreachable software mirrors. You can resolve this by resetting your /etc/apt/sources.list file to the official Ubuntu default mirrors. Below is a configuration for a standard Ubuntu Focal Fossa environment:

deb http://archive.ubuntu.com/ubuntu/ focal main restricted
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ focal universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
deb http://archive.ubuntu.com/ubuntu/ focal multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
deb http://security.ubuntu.com/ubuntu/ focal-security universe
deb http://security.ubuntu.com/ubuntu/ focal-security multiverse

After updating the sources.list file, synchronize the local package index and install the tools with the following sequence:

sudo apt update
sudo apt upgrade
sudo apt install build-essential

Tags: Ubuntu GCC g++ Linux apt

Posted on Thu, 08 Oct 2026 16:49:15 +0000 by allyse