Categories: Ubuntu

How to Install the Boost C++ on Ubuntu 22.04

As a C++ developer, having all the necessary tools to facilitate development is an added advantage. The Boost C++ library contains all the open-source libraries that you require for your C++ development. These libraries come bundled with Boost C++. Once you install it, you can start using the libraries in your code during development.

We will cover the complete installation of Boost C++ on Ubuntu 22.04.

Two Ways of Installing the Boost C++ on Ubuntu 22.04

You have two options to install the Boost C++ library on Ubuntu 22.04. First, you can install it via the Ubuntu apt repository, but that won’t give you the latest release. Alternatively, you can install it from its source code which gives you an access to the latest release.

1.
Sponsored
Install the Boost C++ via APT

Installing it via the apt repository is the most convenient approach for a quick installation of Boost C++ on your Ubuntu 22.04. Start by updating the repository.

$ sudo apt update

The next step is installing the libboost-all-dev package which contains the Boost C++ development libraries.

$ sudo apt install libboost-all-dev

The Boost C++ packages are large in size. Press y to confirm the installation. Ensure an adequate space on your system to accommodate the installation.

Once the package completes the installation, verify that the installation is successful by checking the install Boost C++ version.

$ dpkg -s libboost-dev | grep version

The installed version is 1.74, but that’s not the latest release. To get the latest release, use the second installation method which we will discuss later in this article.

When you install the Boost C++ via APT, you can uninstall the installed package and the dependencies with the following command:

$ sudo apt autoremove libboost-all-dev

2. Install the Boost C++ via Source Code

For someone who are looking to get their hands dirty by installing the latest Boost C++ libraries, you must install them via its source code.

Start by visiting the Boost C++ website and open the “Downloads” section. Locate the option for the “Boost Downloads” and click on the “Current Release”.

A list of available current releases that you can download will appear. Right-click on the “tar.gz” option and copy its link. You can also click on it to start the download.

On your terminal, use wget to download the file via the terminal. Use the link that you copied with the wget command to initiate the download.

Sponsored

Once the download completes, navigate to the download directory. Here, we move the file to our “Downloads” to verify that we downloaded the tar file which contains the source code.

Extract the archive file with the following command:

$ tar xvf boost_1_81_0_tar.gz

Navigate into the extracted “Boots” directory.

$ cd boost_1_81_0/

We must install the required dependencies to support the installation of the Boost C++. Run the following command and all the dependencies will install:

$ sudo apt install build-essential python3-dev g++ autotools-dev libicu-dev libbz2-dev -y

We then need to set up the Boost’s bootstrap. The following command starts the Bootstrap script and builds the B2 engine:

$ sudo ./bootstrap.sh –prefix=/usr/

You can now run the generated B2 engine.

$ ./b2

Lastly, install the Boost C++ using the B2.

$ sudo ./b2 install

Once the program runs, the installation will complete, and you will have the Boost C++ libraries available on your system. You can then invoke them when writing your C++ projects.

Conclusion

The Boost C++ is a handy library to work with C++ projects. It offers different libraries that you can use. We covered two ways of installing it on your Ubuntu 22.04. You can directly install it via APT or using its source code. Use the method that is convenient for your case.

Ubuntu Server Admin

Recent Posts

Microsoft Edge Installation on Ubuntu 24.04

Microsoft Edge is now available for Ubuntu. In this guide, I’ll walk you through the…

10 hours ago

How we used Flask and 12-factor charms to simplify Canonical.com development

Our latest Canonical website rebrand did not just bring the new Vanilla-based frontend, it also…

17 hours ago

Web Engineering: Hack Week 2024

At Canonical, the work of our teams is strongly embedded in the open source principles…

2 days ago

Ubuntu Weekly Newsletter Issue 873

Welcome to the Ubuntu Weekly Newsletter, Issue 873 for the week of December 29, 2024…

3 days ago

How to resolve WiFi Issues on Ubuntu 24.04

Have WiFi troubles on your Ubuntu 24.04 system? Don’t worry, you’re not alone. WiFi problems…

3 days ago

Remembering and thanking Steve Langasek

The following is a post from Mark Shuttleworth on the Ubuntu Discourse instance. For more…

4 days ago