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

Maneesh kushwaha
4 min readJun 6, 2020

--

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

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

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

June 6, 2020 by Editorial Staff

Contents [hide]

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

We hope this post helped you to find out How to Install GCC (build-essential) on Ubuntu 20.04

The GNU Compiler Assortment (GCC) is a group of compilers and libraries for C, C++, Goal-C, Fortran, Ada, Go, and D programming languages. Loads of open-source tasks, together with the Linux kernel and GNU instruments, are compiled utilizing GCC.

This text explains the right way to set up GCC on Ubuntu 20.04.

Installing in GCC on Ubuntu 20.04

The default Ubuntu repositories include a meta-package named “build-essential” that features the GNU compiler assortment, GNU debugger, and different growth libraries and instruments required for compiling software program.

To put in the Growth Instruments packages, run the next command as root or user with sudo privileges:

sudo apt update
sudo apt install build-essential

The command installs plenty of packages, together with gcc, g++ and make.

You might also wish to set up the handbook pages about utilizing GNU/Linux for growth:

sudo apt-get install manpages-dev

Confirm that the GCC compiler is efficiently put in by working the next command that prints the GCC model:

gcc --version

Ubuntu 20.04 repositories provide GCC version 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
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

That’s it. GCC tools and libraries have been installed on your Ubuntu system.

Compiling a Hello World Example

Compiling a primary C or C++ program utilizing GCC is fairly simple. Open your text editor and create the next file:

nano hello.chello.c// hello.c
#include <stdio.h>

int main() {
printf("Hello, world!n");
return 0;
}

Save the file and compile it into an executable:

gcc hello.c -o hello

This creates a binary file named hello in the same directory where you run the command.

Execute the hello program with:

./hello

The program should print:

Hello World!

Installing Multiple GCC Versions

This part gives directions about the right way to set up and use a number of variations of GCC on Ubuntu 20.04. The newer variations of the GCC compiler embrace new capabilities and optimization enhancements.

On the time of writing this text, the default Ubuntu repositories embrace a number of GCC variations, from 7.x.x to 10.x.x. On the time of writing, the newest model og GCC is 10.1.0.

Within the following instance, we’ll set up the newest three variations of GCC and G++.

Set up the specified GCC and G++ variations by typing:

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

The instructions beneath configures various for every model and affiliate a precedence with it. The default model is the one with the best precedence, in our case that’s 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

Later if you want to change the default version use the update-alternatives command:

sudo update-alternatives --config gccThere 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:

You’ll be introduced with an inventory of all put in GCC variations in your Ubuntu system. Enter the variety of the model you wish to be used as a default and press Enter.

The command will create symbolic links to the precise variations of GCC and G++.

Conclusion

We’ve proven you the right way to put in GCC on Ubuntu 20.04. Now you can go to the official GCC Documentation web page and discover ways to use GCC and G++ to compile your C and C++ applications.

We hope the How to Install GCC (build-essential) on Ubuntu 20.04 help you. If you have any query regarding How to Install GCC (build-essential) on Ubuntu 20.04 drop a comment below and we will get back to you at the earliest.

We hope this post helped you to find out How to Install GCC (build-essential) on Ubuntu 20.04 . You may also want to see — How to Set Up a Firewall with UFW on Ubuntu 20.04

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response