How To

Install GCC on Ubuntu: build-essential and Multiple Versions

GCC; the GNU Compiler Collection is the backbone of open-source software development on Linux. It supports multiple programming languages including C, C++, Objective-C, Fortran, Ada, Go, and D. Foundational projects like the Linux kernel and most GNU utilities are compiled with GCC, making it essential for any developer working on a Linux system. This guide shows you how to install GCC on Ubuntu using the build-essential package, compile a test program to verify your setup, and manage multiple GCC versions on the same machine when different projects demand it.

Install GCC on Ubuntu with build-essential

Rather than installing GCC on its own, Ubuntu provides a meta-package called build-essential that bundles everything needed for software compilation in a single install. It includes:

  • gcc – the C compiler
  • g++ – the C++ compiler
  • make – the build automation tool
  • GNU debugger (gdb) and additional development libraries

Run the following commands as a user with sudo privileges:

bashsudo apt updatesudo apt install build-essential

For development work, it is also worth installing the GNU/Linux developer manual pages. These provide quick in-terminal reference for standard library functions and system calls:

bashsudo apt install manpages-dev

Verify the installation by printing the GCC version:

bashgcc --version

On Ubuntu 20.04, the default repositories ship GCC 9.3.0. Seeing the version number in the output confirms your compiler is installed and ready.

Compile and Run a Hello World C Program

The fastest way to confirm your setup works end-to-end is to compile and run a simple C program. Create a new source file:

bashnano hello.c

Paste in the following code:

c#include <stdio.h>int main() {    printf("Hello, World!\n");    return 0;}

Save the file and compile it into an executable binary:

bashgcc hello.c -o hello

The -o hello flag names the output file. Without it, GCC defaults to creating a binary named a.out. Run the compiled program with:

bash./hello

Seeing Hello, World! printed to the terminal confirms GCC is working correctly.

Pro tip: Add the -Wall flag during development to enable all compiler warnings: gcc -Wall hello.c -o hello. Catching warnings at compile time is far faster than tracking down subtle bugs at runtime.

Manage Multiple GCC Versions on Ubuntu

Some projects require a specific GCC version, an older codebase may not compile cleanly with a newer compiler, or you may need the latest release for a specific language feature. Ubuntu’s repositories include GCC versions from 8 through 10, and you can install them side by side.

Install multiple GCC and G++ versions with a single command:

bashsudo apt install gcc-8 g++-8 gcc-9 g++-9 gcc-10 g++-10

Register each version with update-alternatives, assigning priorities that determine which becomes the default. Higher numbers win:

bashsudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8

In this setup, GCC 10 is the active default because it holds the highest priority (100). To switch to a different version at any time, run:

bashsudo update-alternatives --config gcc

An interactive list of installed versions appears. Enter the number next to the version you want and press Enter. The system immediately updates its symbolic links so all GCC-related tools point to your selected version — no reinstallation required.

With GCC and build-essential installed, your Ubuntu system has everything it needs for C and C++ development. You can compile projects from source, contribute to open-source repositories, or experiment with systems-level programming. When your work requires switching between compiler versions, update-alternatives keeps the process clean and reversible. The official GCC documentation covers optimisation flags, cross-compilation, and debugging in depth if you want to go further. Hit an issue? Leave a comment below.

Cyber Defence

Recent Posts

Install Redis on Ubuntu: Configuration and Remote Access

Redis is an open-source, in-memory key-value store built for raw speed and versatility. It works equally well as…

21 hours ago

Install Skype on Ubuntu: Two Methods That Actually Work

Skype doesn't ship with Ubuntu by default it's a proprietary application owned by Microsoft and…

21 hours ago

Install PHP on Ubuntu: Complete Setup Guide for Apache & Nginx

PHP is the backbone of the web. Frameworks like Laravel, WordPress, and Magento all run on…

22 hours ago

Best OSINT Tools for Cybersecurity Teams 2026: Threat Intel and Exposure Checks

Cybersecurity teams use OSINT to see what attackers can already see from public sources. In…

23 hours ago

Best Legal OSINT Tools 2026: Research Safely Without Crossing Privacy Lines

Legal OSINT is about collecting and analyzing publicly available information without bypassing privacy controls, breaking…

23 hours ago

Mono Ubuntu Install: Complete Setup Guide for 20.04

Developers building cross-platform .NET applications often rely on Mono Ubuntu Install to create a flexible…

23 hours ago