YouTube Icon

Code Playground.

How to Install GCC (build-essential) on Ubuntu 20.04


How to Install GCC (build-essential) on Ubuntu 20.04

The GNU Compiler Collection (GCC) is an assortment of compilers and libraries for C, C++, Objective-C, Fortran, Ada, Go , and D programming dialects. A ton of open-source ventures, including the Linux part and GNU apparatuses, are arranged utilizing GCC. 

This article discloses how to introduce GCC on Ubuntu 20.04. 

Installing GCC on Ubuntu 20.04 

The default Ubuntu archives contain a meta-bundle named "fabricate fundamental" that incorporates the GNU compiler assortment, GNU debugger, and other advancement libraries and instruments required for arranging programming. 

To introduce the Development Tools bundles, run the accompanying order as root or client with sudo benefits : 

sudo apt update
sudo apt install build-essential

The order introduces a great deal of bundles, including gcc, g++ and make. 

You may likewise need to introduce the manual pages about utilizing GNU/Linux for improvement: 

sudo apt-get install manpages-dev

Check that the GCC compiler is effectively introduced by running the accompanying order that prints the GCC variant: 

gcc --version

Ubuntu 20.04 stores give GCC rendition 9.3.0: 

gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

That is it. GCC devices and libraries have been introduced on your Ubuntu framework. 

Compiling a Hello World Example

Arranging an essential C or C++ program utilizing GCC is entirely simple. Open your word processor and make the accompanying record: 

nano hello.c


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

Spare the record and gather it into an executable: 

gcc hello.c -o hello

This makes a paired document named hi in a similar registry where you run the order. 

Execute the welcome program with: 


The program should print: 

Hello World!

Installing Multiple GCC Versions

This part gives guidelines about how to introduce and utilize different renditions of GCC on Ubuntu 20.04. The more current adaptations of the GCC compiler incorporate new capacities and streamlining upgrades. 

At the hour of composing this article, the default Ubuntu archives incorporate a few GCC renditions, from 7.x.x to 10.x.x. 

In the accompanying model, we will introduce the most recent three renditions of GCC and G++. 

Introduce the ideal GCC and G++ variants by composing: 

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

The orders underneath arranges elective for every rendition and partner a need with it. The default variant is the one with the most elevated need, for our situation that is gcc-10. 

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

Afterward on the off chance that you need to change the default variant utilize the update-options order: 

sudo update-alternatives --config gcc

There are 3 decisions for the option gcc (giving/usr/receptacle/gcc). 

There are 3 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
* 0            /usr/bin/gcc-10   100       auto mode
  1            /usr/bin/gcc-10   100       manual mode
  2            /usr/bin/gcc-8    80        manual mode
  3            /usr/bin/gcc-9    90        manual mode

Press <enter> to keep the current choice[*], or type selection number:

Press <enter> to keep the current choice[*], or type determination number: 

You will be given elite of all introduced GCC adaptations on your Ubuntu framework. Enter the quantity of the form you need to be utilized as a default and press Enter. 

The order will make emblematic connects to the particular variants of GCC and G++. 


We've told you the best way to introduced GCC on Ubuntu 20.04. You would now be able to visit the authority GCC Documentation page and figure out how to utilize GCC and G++ to arrange your C and C++ programs. 

In the event that you hit an issue or have criticism, leave a remark underneath.