Install build-essential on Ubuntu 22.04 with Easy Steps
This tutorial intends to teach you to Install build-essential on Ubuntu 22.04. If you plan to build a program from the source, you need to have the essential tools for it. The build-essential package provides a set of essential packages and tools required to build or compile software from its source code. The packages include libc, gcc, g++, make, dpkg-dev, etc. You can easily install them in one single package.
Now follow the steps below on the Orcacore website to Install build-essential on Ubuntu 22.04 and see an example of building a package from the source.
To complete this guide for build-essential Ubuntu, you must have access to your server as a non-root user with sudo privileges. For this purpose, you can check this guide on Initial Server Setup with Ubuntu 22.04.
Step 1 – Run Ubuntu System Update
The first step is that your local packages have been up to date. To do this, you can run the system update with the following command:
# sudo apt update
# sudo apt upgrade -y
Step 2 – How To Install build-essential in Ubuntu?
The build-essential Ubuntu package is available in the Ubuntu 22 default repository. You can easily install it on your server by using the following command:
sudo apt install build-essential -y

Step 3 – How To Compile and Build an App from Source?
At this point, we want to show you the process of compiling and building an app from the source. When your installation of the build-essential Ubuntu package is completed, follow the steps below to see how to build an app from the source.
Install Dependencies to build an app from the source
When installing a package from source code, you’ll need to manage the installation of the package dependencies. To do this, you can run the command below:
sudoo apt install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev -y
Now follow the steps below to build your app on Ubuntu:
./configure
make
make install
That’s it, you are done.
Why is better to build an app from source code instead of downloading it as a package?
Maybe your package manager depends on your OS doesn’t have the available package. So it is recommended to build your package from the source in the latest version. Also, you can control your package by yourself.
Conclusion
At this point, you have learned to Install the build-essential package on Ubuntu 22.04 with these easy guide steps, install the dependencies for building a package, and compile and build a program for the source. Hopefully, this article helped you learn how to Install build-essential on Ubuntu 22.04.
Hope you enjoy using it. You may also interested in reading these articles:
Install Etherpad on Ubuntu 22.04
Install Mattermost on Ubuntu 22.04
Fix download is performed unsandboxed as root as file
Fix modulenotfounderror: no module named ‘distutils’
Alternative Approaches to Installing Build Tools on Ubuntu 22.04
While the build-essential
meta-package provides a convenient way to install common build tools, there are alternative approaches that offer more granular control and flexibility. These methods are especially useful when dealing with specific project requirements or when aiming for a minimal installation. Here are two alternative approaches to consider beyond the standard build-essential
installation on Ubuntu 22.04:
1. Installing Individual Tools with apt
Instead of relying on the build-essential
meta-package, you can install the necessary tools individually using apt
. This approach provides precise control over which components are installed, allowing you to tailor the build environment to specific project needs. For example, if you only need gcc
, make
, and libc-dev
, you can install just those packages. This is particularly useful in environments where disk space is limited or when adhering to strict security policies.
Explanation:
This method involves identifying the exact tools and libraries required for your specific build process and installing them one by one using apt
. This eliminates the installation of potentially unnecessary components included in the build-essential
package. This approach helps in creating a leaner and more controlled development environment.
Code Example:
Let’s say you need to compile a simple C program. You’ll likely need gcc
, make
, and the C standard library development headers (libc6-dev
). To install these individually, use the following command:
sudo apt install gcc make libc6-dev -y
This command will install only the specified packages and their dependencies, avoiding the larger footprint of the build-essential
meta-package. After installing these core components, you can test if your C program can be built successfully.
Here’s a sample C program (hello.c
):
#include <stdio.h>
int main() {
printf("Hello, World!n");
return 0;
}
Compile and run the program:
gcc hello.c -o hello
./hello
If the program compiles and runs successfully, it confirms that you have the necessary tools installed for basic C development. You can extend this principle to install other tools as needed for more complex projects. For example, for C++ development, install g++
instead of gcc
. For projects requiring debugging capabilities, install gdb
.
2. Using Containerization with Docker
Another powerful alternative is to utilize containerization technology like Docker. Docker allows you to create isolated environments containing all the necessary build tools and dependencies for your project. This approach ensures consistency across different development environments and simplifies the build process, especially when dealing with complex dependencies or cross-compilation scenarios.
Explanation:
Docker containers encapsulate your build environment, including the operating system, libraries, tools, and configurations. This eliminates dependency conflicts and ensures that your build process is consistent regardless of the underlying host system. This method is particularly advantageous for team projects where different developers might be using different operating systems or software versions.
Code Example:
First, you’ll need to install Docker on your Ubuntu system. Instructions for installing Docker can be found on the official Docker website. Once Docker is installed, you can create a Dockerfile
that defines the build environment for your project.
Here’s a sample Dockerfile
for building a C++ application:
FROM ubuntu:22.04
# Update package list and install build tools
RUN apt-get update && apt-get install -y
build-essential
cmake
git
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy source code
COPY . .
# Build the application
RUN cmake .
RUN make
# Command to run the application
CMD ["./my_application"]
Explanation of the Dockerfile:
FROM ubuntu:22.04
: Specifies the base image as Ubuntu 22.04.RUN apt-get update && apt-get install -y ...
: Updates the package list and installs the necessary build tools, includingbuild-essential
,cmake
(for managing the build process), andgit
(for version control). The&& rm -rf /var/lib/apt/lists/*
part cleans up the apt cache to reduce the image size.WORKDIR /app
: Sets the working directory inside the container to/app
.COPY . .
: Copies all files from the current directory (where theDockerfile
is located) to the/app
directory inside the container.RUN cmake . && make
: Configures and builds the application using CMake andmake
. Replace these commands with the appropriate build commands for your specific project.CMD ["./my_application"]
: Defines the command to run when the container starts. Replace"./my_application"
with the actual name of your executable.
Building and Running the Docker Image:
- Save the
Dockerfile
in the root directory of your project. -
Open a terminal in the same directory and run the following command to build the Docker image:
docker build -t my_app .
This command builds an image named
my_app
using theDockerfile
in the current directory. -
After the image is built, you can run it using the following command:
docker run my_app
This command starts a container from the
my_app
image and executes the command specified in theCMD
instruction of theDockerfile
.
By using Docker, you can ensure that your application is built and runs consistently across different environments, regardless of the host operating system or installed software. This eliminates the "it works on my machine" problem and simplifies the deployment process. Furthermore, Docker enables easier collaboration within development teams and facilitates continuous integration and continuous deployment (CI/CD) workflows.
In conclusion, while the build-essential
package offers a quick and easy way to install common build tools on Ubuntu 22.04, installing individual tools with apt
or leveraging containerization with Docker provides more flexibility and control, especially for specific project requirements or complex development environments. Choosing the right approach depends on the specific needs of your project and the desired level of control over the build environment. These methods allow for more precise and potentially cleaner installations.