How to Install Build Essentials on Ubuntu 22.04?
Build Essential is a collection of tools/packages to compile source code of different languages. The source code is compiled first, and then the utilities (such as make) inside the Build-Essential allow you to install the package from the compiled source code. Build Essential supports the programs written in C/C+, Fortran, Objective-C, Go, Assembler, etc.
Apart from the compilation support, Build Essential is equipped with a utility named “dpkg-dev” to build/compile the source packages on Ubuntu (and other Debian-based systems).
Keeping in view the importance of the Build-Essential, this post will demonstrate the installation of the Build-Essentials on Ubuntu 22.04 (Jammy Jellyfish).
Why Build Essential? | Importance of Build-Essential
Build-Essential comprises tools gcc, g++, libc6-dev, and dpkg-dev. All these tools have a specific purpose and role in Ubuntu 22.04. Let’s discuss how they assist Ubuntu (Debian) users:
- Compilation of C/C++: The GNU C and GNU C++ tools help in compiling the C/C++ programs in your system.
- Building Packages from Source Code: In Ubuntu (and other Debian-based systems), the users have to build the source code to install a package (if its source code is available and the package is not available in the default repositories). For this, the make utility in Build-Essential allows you to read the makefile and follow the instructions in it to install the package on your system.
- Maintain Debian Packages: The dpkg-dev tool in Build-Essential creates and distributes (maintains) the Debian packages.
- Standard GNU C/C++ Library: The libc6-dev tool in build-essential refers to the Standard GNU C/C++ library which helps in integrating the additional support while compiling C/C++ programs.
Why install them one by one when you have the Build-Essential? Let’s do it:
How to Install Build-Essential on Ubuntu 22.04?
By default, some of the packages available in the Build-Essential are already installed on Ubuntu 22.04 (Jammy Jellyfish). However, the Build-Essential as a whole needs to be installed properly following the below-stated steps.
First, update the system’s packages list to load the latest available versions:
$ sudo apt update
Now, use the below-stated command to install build-essential:
$ sudo apt install build-essential
Look at the output, a few packages are already available and being upgraded to their latest versions. The missing packages have also been installed.
By default, the Build-Essential tool provides the compilation of C/C++ programs. The extensive support of Build-Essential support for other compilers (Fortran/Objective-C) needs to be embedded and can be installed with the command:
$ sudo apt install gobjc gfortran gnat
Now, your Ubuntu 22.04 is equipped with compilers for the programs, i.e., C, C++, Fortran, and Objective-C. To verify the installation of build-essential, check its existence in the list of installed packages via the command:
$ sudo apt list --installed | grep build-essential
Let’s learn how you can use it on Ubuntu 22.04.
How to Use Build Essential on Ubuntu 22.04?
Build-Essential is not directly launched from the terminal or used as a separate entity like other tools on Ubuntu. As discussed, it contains building/compiling utilities that are used individually as per their purpose. Let’s discuss the usage of the G++ (C++ Compiler) inside the Build-Essential:
G++ compiler resides in the Build-Essential package, used to compile the C++ code. Let’s use it on Ubuntu 22.04:
The C++ files end with an extension “.cc”. As an example, the following C++ source code would be compiled:
Let’s compile the code in the file named “linuxgenie” via the command provided below:
$ g++ -o linuxgenie genie.cc
Similarly, while installing any program from the source code. You must have used the “make” and “make install” commands. The “make” utility is the part of Build-Essential package. Thus, the “make” associated commands only work when the build-essential is installed on your system.
How to Install Build-Essential on Other Linux Distributions?
The Build-Essential package name is only associated with the Debian/Ubuntu-based distributions. However, the support is available on other Linux distributions but with different names. Let’s see how you can install them on other Linux distributions:
RHEL/RedHat/CentOS/Fedora
For the yum-supported distributions:
$ sudo yum groupinstall 'Development Tools'
For dnf supported distributions:
$ sudo dnf group install "C Development Tools and Libraries" "Development Tools"
Arch-Based Distributions:
$ sudo pacman -Sy base-devel
OpenSUSE-Based Distributions
$ sudo zypper install -t pattern devel_basis
How to Boost the C/C++ Compilers on Ubuntu 22.04?
Cache stores the data temporarily which needs to be cleared for the performance boost. Like other programs, compilers do have a cache. Ubuntu (and other Debian-based distributions) offer a utility named “ccache” which is used to compile C/C++ programs more speedily than just a simple compiler. Let’s see how to install it:
$ sudo apt install ccache
How to Use ccache on Ubuntu 22.04?
The “ccache” is utilized with the normal compilers (gcc/g++) to speed up the compilation process. The syntax to use the “ccache” is provided below:
$ ccache gcc <c++-file>
Just add the keyword “cache” before the compiler name, i.e., g++/gcc.
How to Remove Build-Essential From Ubuntu 22.04?
Build-essential is a useful tool that contains various essentials for Debian-based packages. However, if you think, it is unnecessary on your system. Use the command to remove it from Ubuntu 22.04:
$ sudo apt autoremove build-essential
That’s all about the installation/usage/configuration of Build Essential on Ubuntu 22.04.
Bottom Line
Build-Essential is a set of tools comprising two basic compilers (C/C++), one standard library (libc6-dev), and a Debian package maintainer (dpkg-dev). It is available on the default repository of Ubuntu and is installed using the command “sudo apt install build-essential”. These tools are useful while compiling the source code or building/maintaining the Debian packages.
This post has demonstrated the installation, usage, and removal of Build-Essential on Ubuntu 22.04.