How to install build-essential in Ubuntu?

The build-essential package is a reference for all the packages needed to compile a package in Ubuntu or other Linux distribution. It generally includes the gcc/g++ compilers and libraries and some other tools to compile/build software.

It is a meta-package available in the default Ubuntu repository that includes GNU compiler collection, GNU debugger, and other development libraries and tools required for compiling software.

In this article, I will discuss how to install build-essential on Ubuntu.

Installing build-essential in Ubuntu

Before you install build-essential on your system run the given command to update the local package database –

sudo apt update

Now use the following command to install build-essential –

sudo apt install build-essential -y

You can verify the installation by using –

gcc --version

gcc version

Check g++ compiler by using –

g++ --version

g++ version

Compile and run a sample program

We will compile and run a simple hello world program which is written in C. Open a text editor and copy the given code, save it with .c extension.

#include <stdio.h>

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

You can see this in the image below.

sample c program

Now compile this program into an executable.

gcc sample.c -o sample

This will create a binary file in your current working directory.

Use the given command to execute this program –

./sample

You can see the output of this program in the given image –

output

To compile and install complex softwares such as Ruby, OpenCV, etc from the source you need to have build-essential with some other tools like CMake installed on your system.

Conclusion

So here we have discussed what build-essential is and why it is necessary for compiling softwares. You also learned how to install it on a Ubuntu system.

Now for any queries write us in the comments below.

Leave a Comment