How to Install the build-essential Package on Ubuntu
Every OS has in-built dependencies to function smoothly. In short, these supporting programs are often required to compile software and ensure all dependent software is available when needed.
Ubuntu’s build-essential meta-package includes several such packages, which ensure your Linux experience is as seamless as you would like it to be. These packages are a part of Debian and contain all the components you need to create a Debian package.
On Ubuntu, there are a series of five packages included in the build-essential meta-package:
- dpkg-dev: You can use this package to unpack, build, and even upload DEB source packages. You can essentially use this utility for packaging 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 provide working directions to the compiler. During installation, ensure to address any make: command not found errors.
- libc6-dev: The libc6-dev is the GNU C library that contains 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, respectively.
Once you install the essential packages on your system, you can create C++ scripts to check the status and installation extent.
Alternatively, there is no hard and fast rule against installing each software separately. However, since the build-essential package comes as a bundled list of software, you will have everything in one place, which is convenient.
How to Install build-essential on Ubuntu
When you need to install the build-essential meta-package on Ubuntu, you can follow the steps listed below:
Install any pending updates for your existing packages with the update and upgrade 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 permission to install specific packages. Type y to grant permission. You’ll also notice a lot of commands for package unpacking and setting up. It’s almost like filling in the gaps within your Linux ecosystem.
As a next step, you can install the manual pages to assist you with the build-essential package installation. This is an optional step, in case you don’t wish to install it.
sudo apt install manpages-dev
Now that all the packages are installed, you can check the GCC version with the following command:
The output is as below:
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Since you are already checking the GCC version, it’s also advisable to check the g++ version with the –version command:
The version numbers are towards the end of the string, similar to 11.2.0. The version numbers will differ, based on the Ubuntu version you are using.
Since the compiler libraries are installed, you can run a C program to check the installation parameters.
Running a C Script Using GCC
To confirm if the build-essential meta-package was successfully installed, 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:
Add the following code snippet within the text editor and save the script:
printf("Hi, This is a test compiler program in C compiler!
Here’s what the text file should look like:
Here’s a brief explanation of the program:
- stdio.h: Standard input-output library header
- main(): This function runs the C program
- printf(): A C function to print an output
- n: Prints the output on a new line
To save, simply press Ctrl + X, followed by Y and Enter.
Next, you need to make an executable file as follows:
gcc test.c -o test
Run the newly created C file with the command:
The output saved and compiled in the text editor is published on the terminal window successfully. This proves that the installation of the GCC compiler was successful.
How to Uninstall build-essential From Ubuntu
Finally, there might be situations wherein you want to uninstall the packages 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 the installed packages. Additionally, it will also be useful for you to run the autoremove command to remove the residual packages:
sudo apt autoremove
The build-essential programs on Ubuntu continue to be an integral part of your regular code compilation and software installation.
Since these packages form the base for any execution, it’s important you install them as soon as you upgrade to any new Ubuntu release or move from another OS to Linux, especially Windows, to avoid unwanted lags and compilation errors.