Site icon DesignLinux

How to Install GCC on Ubuntu 20.04

How to Install GCC on Ubuntu 20.04

GCC, or GNU Compiler Collection is a compiler system for C, C++, Objective-C, Objective-C++, Fortran, Ada, D, Go, and BRIG (HSAIL) programming languages. It’s produced by the GNU Project and the current version is GCC 9.3. In this article we will explain how to install GCC on Ubuntu 20.04.

Installing GCC on Ubuntu 20.04

The build-essential package is available in default Ubuntu repositories. It includes GNU compiler collection and entire development package.

Run the below command to install the Development Tools packages as root or user with sudo privileges:

sudo apt update
sudo apt install build-essential

Once the installation is complete, you can verify the version by typing:

gcc --version

It should print the following output:

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.

At this point, GCC tools and libraries are installed on your Ubuntu system.

Test Compiling

To test a compiling, Let’s create a small program. Open your text editor and create the following file:

nano welcome.c
#include <stdio.h>
 
int main() {
    printf("You're welcome!\n");
    return 0;
}

Save it as welcome.c and compile it using following command:

gcc -o welcome welcome.c

The above command will create a binary file named welcome in the current working directory.

To execute program, type:

./welcome

It will show output:

You're welcome!

Conclusion

This tutorial covers how to install GCC on Ubuntu 20.04 system and how to create a C or C++ program using GCC.

To know more about to use GCC and G++ to compile your C and C++ programs visit the official GCC Documentation.

If you have any problem or feedback, please leave a comment below.

Exit mobile version