How to Install the build-essential Package on Ubuntu

Every operating system has built-in dependencies to run smoothly. In short, these supporting programs are often needed to compile software and ensure that all dependent software is available when needed.

Ubuntu’s Build Essential metapackage contains several such packages, ensuring your Linux experience is as seamless as you want it to be. These packages are part of Debian and contain all the components you need to build a Debian package.


On Ubuntu there is a set of five packages included in the build-essential metapackage:

  • dpkg-dev: You can use this package to unzip, build and even upload DEB source packages. You can essentially use this utility to package your software for Debian-based systems.
  • make: The make tool is an integral part of Linux that creates and interprets makefiles. Makefile is necessary to give the compiler working instructions. During the installation, make sure to fix any make: command not found errors.
  • libc6-dev: libc6-dev is the GNU C library containing the necessary header files and development libraries to process and compile C and C++ scripts.
  • gcc/g++: These are the compilers for C and C++ scripts.


Once you have the essential packages installed on your system, you can create C++ scripts to check the status and scope of the installation.

Alternatively, there is no hard and fast rule against installing each software separately. However, since the Build Essential pack comes as a bundled software list, you have everything in one place, which is handy.

How to install build-essential on Ubuntu

If you need to install the build-essential metapackage on Ubuntu, you can follow the steps below:

Install any pending updates to your existing packages using the To update and Update Commands:

sudo apt update && sudo apt upgrade -y

To install build-essential you can use the following command:

sudo apt install build-essential

During the installation phase, the compiler asks for permission to install specific packages. Type j to grant permission. You will also notice many commands for unpacking and setting up packages. It’s almost like filling in the blanks in your Linux ecosystem.

As a next step, you can install the manual pages to help you install the build-essential package. This is an optional step if you don’t want to install it.

sudo apt install manpages-dev

After all packages are installed, you can check the GCC version with the following command:

gcc 

The output is as follows:

gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0

Since you’re already checking the GCC version, it’s a good idea to check the g++ version with the as well –Execution Command:

g++ 

The version numbers are at the end of the string, similar to 11.2.0. The version numbers differ depending on the version of Ubuntu you are using.

Since the compiler libraries are installed, you can run a C program to check the installation parameters.

Running a C script with GCC

To confirm whether the build-essential metapackage was installed successfully, you can write and compile a sample C script. Open your favorite text editor on Ubuntu. You can choose between Vim and Nano to write the following code snippet:

nano test.c

Add the following code snippet in the text editor and save the script:

#include <stdio.h>
void main()
{
printf("Hi, This is a test compiler program in C compiler!
");
}

The text file should look like this:

Here is a brief explanation of the program:

  • stdio.h: Standard input-output library header
  • mainly(): This function executes the C program
  • printf(): AC function to print an output
  • \n: Prints the output on a new line

Just press to save Ctrl + Xfollowed by Y and Enter.

Next you need to create an executable file like this:

gcc test.c -o test

Run the newly created C file with the command:

./test

The output saved in the text editor and compiled is successfully published in the terminal window. This proves that the GCC compiler installation was successful.

How to uninstall build-essential from Ubuntu

Finally, there may be situations where you want to uninstall the packages that were installed during the Build Essential package installation. In such a scenario, you can use the basic command:

sudo apt remove build-essential

This should remove all installed packages. In addition, it is also useful for you to run the autoremove command to remove the remaining packages:

sudo apt autoremove

The Build Essential programs on Ubuntu continue to be an essential part of your regular code compilation and software installation.

Since these packages form the basis of any execution, it is important that you install them whenever you upgrade to a new Ubuntu version or switch to Linux from another operating system, especially Windows, to avoid unwanted delays and compilation errors.

Leave a Reply

Your email address will not be published. Required fields are marked *