How to install the latest Boost library on Ubuntu

At the time of writing, the latest version of Boost library in the official Personal Package Archive (PPA) is 1.55.

$> aptitude search boost
p libboost1.55-all-dev - Boost C++ Libraries development files (ALL)

Which is far from the latest. To install the newest Boost version (including all libraries), you need to download the latest source code from Boost website (currently the latest version is 1.69.0).

$> cd /tmp/
$> wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
$> tar xzvf boost_1_69_0.tar.gz

Now you need to specify where to put the included headers and libraries, after compiling the source code.

$> ./bootstrap.sh --prefix=/usr/

Let’s build the source code (that takes a while).

$> ./b2

The final step is to install the headers and libraries or copy them to the location specified with the –prefix command line option.

$> sudo ./b2 install

Check installed Boost version

Now you have installed the latest version of Boost, let’s try to compile C++ source code to print the Boost version to verify that all works fine.

#include <boost/version.hpp>
#include <iostream>

int main()
{
  std::cout << "Boost version: " << BOOST_VERSION / 100000
            << "." << BOOST_VERSION / 100 % 1000 << "."
            << BOOST_VERSION % 100 << std::endl;

  return 0;
}
$> g++ -Wall -g -ggdb -Werror -std=c++11 -o get_boost_version get_boost_version.cpp
$> ./get_boost_version
Boost version: 1.69.0