How to Install build-essential on Ubuntu 16.04/18.04 Linux

This post will guide you how to install build-essential package on your Ubuntu 16.04/18.04 Linux server. How do I install GCC or G++ compiler via installing build-essential package on your Ubuntu Linux.

What is build-essential?


The build-essentials package is a reference for all the packages needed to compile a Debian package. It generally includes the GCC/g++ compilers and libraries and some other utilities. So if you need to install C/C++ compiler, you just need to install build-essential package on your machine. And the build-essential is a metapackage that installs many other packages, like G++, GCC, dpkg-dev, make,etc.

Install build-essential Package


The build-essential package is already available on the default Ubuntu repository. so you just need to install it with the apt install command. Before installing build-essential package, you need to update the Ubuntu repo index with the following command:

$ sudo apt update

Then type the following commmand to install build-essential package:

$ sudo apt install build-essential

Outputs:

devops@devops-osetc:~$ sudo apt install build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libllvm6.0 x11proto-dri2-dev x11proto-gl-dev
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
build-essential
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,758 B of archives.
After this operation, 20.5 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu bionic/main amd64 build-essential amd64 12.4ubuntu1 [4,758 B]
Fetched 4,758 B in 1s (3,325 B/s)
Selecting previously unselected package build-essential.
(Reading database ... 231616 files and directories currently installed.)
Preparing to unpack .../build-essential_12.4ubuntu1_amd64.deb ...
Unpacking build-essential (12.4ubuntu1) ...
Setting up build-essential (12.4ubuntu1) ...

Check GCC Version

After the installation process is completed, you can confirm your installation by checking for GCC version with the following command:

$ gcc --version

Outputs:

devops@devops-osetc:~$ gcc --version
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 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.

Let’s write a simple C program as below:

#include <stdio.h>

int main()
{
    printf("Hell, World!\n ");
}

Save this program as test.c file in your Ubuntu system, and try to execute the following command to compile and execute it:

$ gcc -o test test.c
$ ./test

Outputs:

devops@devops-osetc:~$ gcc -o test test.c
devops@devops-osetc:~$ ./test
Hell, World!

Conclusion


You should know that how to install build-essential on your Ubuntu 14.04 or 16.04 or 18.04 Linux from this guide. And if you want to learn more about the build-essential, you can go the below official web site to checking the getting started guide directly.

You might also like:

Sidebar



back to top