How to Install Boost on Ubuntu

Install Boost on Ubuntu with libboost-all-dev from apt for Boost 1.83 headers and libraries, or build Boost 1.87 from archives.boost.io with bootstrap.sh and b2: verify with a small C++ program, link with g++ or CMake, and avoid mixing prefixes without -I and -L.

Published

Updated

Read time 8 min read

Reviewed byDeepak Prasad

Install Boost on Ubuntu banner with C++ Boost libraries icon and Ubuntu orange accent

Boost is a collection of peer-reviewed C++ libraries—filesystem, threading, regex, ASIO, and many more—under the permissive Boost Software License. On Ubuntu you usually install Boost in one of two ways: libboost-all-dev from apt (fast, supported, tied to the distro version) or a source build from archives.boost.io when you need a specific release or build flags.

This guide walks through both paths on Ubuntu 25.04. I installed Boost 1.83.0 from apt and built Boost 1.87.0 from the official tarball with bootstrap.sh and b2, keeping real terminal output below so you can compare your machine.

Tested on: Ubuntu 25.04 (Plucky Puffin); kernel 6.14.0-37-generic.

NOTE
./b2 install writes under the --prefix you chose—typically /usr/local. Run it with sudo unless you set --prefix to a directory you own (for example $HOME/.local). On my first attempt without sudo, b2 failed after ~19 seconds when it could not create /usr/local/include/boost.

Quick command summary

Task Command
Install all Boost dev packages (apt) sudo apt install -y libboost-all-dev
Check apt candidate version apt-cache policy libboost-all-dev
List installed Boost shared libs ls /usr/lib/x86_64-linux-gnu/libboost_system.so*
Download Boost 1.87.0 source wget https://archives.boost.io/release/1.87.0/source/boost_1_87_0.tar.gz
Extract tarball tar -xf boost_1_87_0.tar.gz
Install build dependencies sudo apt install -y build-essential g++ python3-dev libicu-dev libbz2-dev
Bootstrap B2 cd boost_1_87_0 && ./bootstrap.sh --prefix=/usr/local
Build and install (subset, faster) sudo ./b2 -j$(nproc) --with-system --with-filesystem variant=release link=shared threading=multi install
Build and install (full tree) sudo ./b2 -j$(nproc) variant=release link=shared threading=multi install
Verify headers compile g++ boost_test.cpp -o boost_test && ./boost_test
Remove apt install sudo apt purge -y libboost-all-dev && sudo apt autoremove -y

Prerequisites

  • Ubuntu 22.04 LTS, 24.04 LTS, or newer (25.04 tested here) on amd64. Other architectures use the same apt package names with arch-specific library paths.
  • sudo for apt and for installing under /usr or /usr/local.
  • g++ from build-essential (Ubuntu 25.04 ships g++ 14.2.0).
  • Disk space: apt install pulls hundreds of megabytes with MPI-related dependencies; a full source build needs several gigabytes under the build tree plus install prefix.
  • Outbound HTTPS to archive.ubuntu.com and archives.boost.io (or wget for the tarball).

APT vs source build

APT (libboost-all-dev) Source (bootstrap.sh + b2)
Boost version Distro-pinned (1.83 on 25.04) Any release on archives.boost.io
Install time Minutes Tens of minutes to hours (full build)
Updates sudo apt upgrade Rebuild and reinstall manually
Best for Most C++ projects on Ubuntu Bleeding-edge Boost or custom b2 flags

For day-to-day development on Ubuntu, start with apt. Move to source when a tutorial or upstream project names a newer Boost than your archive provides.


Step 1: Install Boost from the Ubuntu repository

Refresh indexes and install the meta-package that pulls Boost headers and development symlinks for every bundled library:

bash
sudo apt update
sudo apt install -y libboost-all-dev

On Ubuntu 25.04 the candidate before install was 1.83.0.2ubuntu1. The tail of apt install finished with:

text
Setting up libboost-all-dev (1.83.0.2ubuntu1) ...
Processing triggers for man-db (2.13.0-1) ...
Processing triggers for libc-bin (2.41-6ubuntu1.2) ...

Confirm the package and peek at a common library:

bash
dpkg -s libboost-all-dev | grep -E '^Version|^Status'
ls /usr/lib/x86_64-linux-gnu/libboost_system.so*
text
Status: install ok installed
Version: 1.83.0.2ubuntu1
/usr/lib/x86_64-linux-gnu/libboost_system.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.83.0
HINT
libboost-all-dev is heavy—it drags MPI and parallel graph stacks you may never use. When you only need one component, install targeted packages such as libboost-system-dev or libboost-filesystem-dev instead of the all-in-one metapackage.

Verify the apt install

Create a small test program:

bash
cat > /tmp/boost_test.cpp << 'EOF'
#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;
}
EOF

g++ /tmp/boost_test.cpp -o /tmp/boost_test
/tmp/boost_test
text
Boost version: 1.83.0

boost/version.hpp is header-only for this check—no -lboost_* linker flag required.


Step 2: Build and install Boost from source

Use this when you need a release newer than apt ships. Downloads now live on archives.boost.io (the old JFrog URLs still redirect, but the archives host is the stable path cited in current Boost docs).

Download and extract

Pick a version from the Boost release page and adjust the URL. For 1.87.0:

bash
cd /tmp
wget https://archives.boost.io/release/1.87.0/source/boost_1_87_0.tar.gz
tar -xf boost_1_87_0.tar.gz
cd boost_1_87_0

The archive is about 148 MB compressed; extraction creates a boost_1_87_0/ directory with bootstrap.sh, b2, and the library sources. See the tar command guide if you prefer tar -xvf for verbose listing.

Install build dependencies

Boost’s build system (B2) needs a C++ toolchain, Python headers, and ICU/bzip2 for some libraries:

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

On my host these packages were already present from the apt Boost install; apt reported 0 newly installed.

Bootstrap B2

Choose an install prefix. /usr/local keeps source Boost separate from apt’s /usr tree:

bash
./bootstrap.sh --prefix=/usr/local

Near the end of bootstrap:

text
Generating B2 configuration in project-config.jam for gcc...

Bootstrapping is done. To build, run:

    ./b2

To generate header files, run:

    ./b2 headers

Bootstrap took about 80 seconds on this VM; g++ reported as 14.2.0.

Compile and install with b2

A full b2 install builds every library and can take a long time. For a quicker proof, limit libraries with --with-*:

bash
sudo ./b2 -j"$(nproc)" \
  --with-system \
  --with-filesystem \
  variant=release \
  link=shared \
  threading=multi \
  install

Without sudo, my install failed when b2 could not create /usr/local/include/boost—the log ended with ...failed updating 5 targets... and common.mkdir /usr/local/include/boost.

With sudo, the same command succeeded in about two minutes for this subset. The tail looked like:

text
common.copy /usr/local/lib/libboost_filesystem.so.1.87.0
ln-UNIX /usr/local/lib/libboost_filesystem.so
common.copy /usr/local/lib/libboost_system.so.1.87.0
ln-UNIX /usr/local/lib/libboost_system.so

...updated 17217 targets...

Installed libraries:

bash
ls -la /usr/local/lib/libboost_system.so* /usr/local/lib/libboost_filesystem.so*
text
lrwxrwxrwx 1 root root     29 ... /usr/local/lib/libboost_filesystem.so -> libboost_filesystem.so.1.87.0
-rwxr-xr-x 1 root root 216144 ... /usr/local/lib/libboost_filesystem.so.1.87.0
lrwxrwxrwx 1 root root     25 ... /usr/local/lib/libboost_system.so -> libboost_system.so.1.87.0
-rwxr-xr-x 1 root root  15144 ... /usr/local/lib/libboost_system.so.1.87.0

To install everything, drop the --with-* filters and budget substantially more time and CPU:

bash
sudo ./b2 -j"$(nproc)" variant=release link=shared threading=multi install
IMPORTANT
Installing with --prefix=/usr overlays apt’s Boost under /usr/lib and /usr/include. Prefer /usr/local or $HOME/.local unless you deliberately replace the distro packages and understand the breakage risk for apt upgrade.

Verify the source install

Link against the /usr/local build explicitly:

bash
cat > /tmp/boost_local_test.cpp << 'EOF'
#include <boost/version.hpp>
#include <boost/filesystem.hpp>
#include <iostream>

int main() {
    std::cout << "Boost version: "
              << BOOST_VERSION / 100000 << "."
              << BOOST_VERSION / 100 % 1000 << "."
              << BOOST_VERSION % 100 << std::endl;
    std::cout << "exists /tmp: "
              << boost::filesystem::exists("/tmp") << std::endl;
    return 0;
}
EOF

g++ /tmp/boost_local_test.cpp -o /tmp/boost_local_test \
  -I/usr/local/include -L/usr/local/lib \
  -lboost_filesystem -lboost_system

LD_LIBRARY_PATH=/usr/local/lib /tmp/boost_local_test
text
Boost version: 1.87.0
exists /tmp: 1

If you omit -I/usr/local/include, g++ may pick 1.83.0 headers from /usr/include even after a successful 1.87 install—always align include and library paths with the Boost tree you intend to use.


Step 3: Use Boost in your projects

g++ one-liner (apt Boost, filesystem example):

bash
g++ main.cpp -o app -lboost_filesystem -lboost_system

CMake (source install under /usr/local):

cmake
cmake_minimum_required(VERSION 3.16)
project(demo CXX)
set(CMAKE_PREFIX_PATH "/usr/local")
find_package(Boost 1.87 REQUIRED COMPONENTS filesystem system)
add_executable(demo main.cpp)
target_link_libraries(demo Boost::filesystem Boost::system)

For apt Boost, find_package(Boost 1.83 REQUIRED COMPONENTS filesystem) usually works without CMAKE_PREFIX_PATH because Ubuntu ships CMake config files under /usr/lib/x86_64-linux-gnu/cmake/.


Uninstall

APT:

bash
sudo apt purge -y libboost-all-dev
sudo apt autoremove -y

Source install under /usr/local (adjust if you used another prefix):

bash
sudo rm -rf /usr/local/include/boost
sudo rm -f /usr/local/lib/libboost_* /usr/local/lib/cmake/Boost-*
sudo rm -rf /usr/local/lib/cmake/boost_*

If you still have the extracted source tree, sudo ./b2 --prefix=/usr/local uninstall can remove files B2 installed—handy when you built the full set.


Troubleshooting

Symptom Likely cause Fix
b2 install fails on common.mkdir /usr/local/... No write permission to prefix Prefix with sudo or use --prefix=$HOME/.local
Program links 1.83 but you built 1.87 Default include path prefers /usr/include Pass -I/usr/local/include -L/usr/local/lib and set LD_LIBRARY_PATH or rpath
undefined reference to boost::... Missing -lboost_* Add the library component (-lboost_filesystem, etc.) or use CMake imported targets
apt install libboost-all-dev pulls MPI stacks Metapackage depends on optional parallel libs Install specific libboost-<name>-dev packages instead
Old wget URL from JFrog times out Expired signed S3 redirect Use https://archives.boost.io/release/<ver>/source/boost_<ver>_0.tar.gz
Full b2 build runs for hours Expected for all libraries Use --with-<library> filters during development

References


Summary

On Ubuntu, sudo apt install libboost-all-dev is the practical default—it delivered Boost 1.83.0 on 25.04 with headers under /usr/include/boost and shared libraries in /usr/lib/x86_64-linux-gnu/. When you need a newer release or custom B2 options, download the tarball from archives.boost.io, run ./bootstrap.sh --prefix=/usr/local, then sudo ./b2 install—and remember that without sudo the install step stops at the first /usr/local directory it cannot create.

After either path, compile a tiny program that includes boost/version.hpp (and link libboost_filesystem when you exercise non-header-only APIs) so you know which version and prefix your compiler actually picked.

Frequently Asked Questions

1. How do I install Boost on Ubuntu?

Run sudo apt update && sudo apt install -y libboost-all-dev for headers and libraries from the Ubuntu archive. For a newer release, download the tarball from archives.boost.io, run ./bootstrap.sh --prefix=/usr/local, then sudo ./b2 install in the extracted source tree.

2. What is the apt package name for Boost on Ubuntu?

libboost-all-dev installs the full Boost development stack. libboost-dev is the default-version metapackage; pick individual libboost--dev packages when you only need system, filesystem, thread, or similar components.

3. Which Boost version does Ubuntu ship?

On Ubuntu 25.04 apt installs Boost 1.83.0 via libboost-all-dev 1.83.0.2ubuntu1. Ubuntu 22.04 LTS also tracks the 1.74 or 1.83 line depending on release—run apt-cache policy libboost-all-dev before you assume a version.

4. How do I build Boost from source on Ubuntu?

Install build-essential g++ python3-dev libicu-dev libbz2-dev, extract the release tarball, run ./bootstrap.sh --prefix=/usr/local, then sudo ./b2 -j$(nproc) variant=release link=shared threading=multi install. Without sudo the install step fails when b2 tries to write under /usr/local.

5. Where are Boost libraries installed on Ubuntu?

APT packages place shared libraries under /usr/lib/x86_64-linux-gnu/ with headers in /usr/include/boost. A source build with --prefix=/usr/local installs to /usr/local/lib and /usr/local/include/boost. Point the compiler with -I and -L or CMAKE_PREFIX_PATH when you use the non-default prefix.

6. How do I verify Boost is installed correctly?

Compile a short program that includes boost/version.hpp and prints BOOST_VERSION, or link against libboost_filesystem and call boost::filesystem::exists. Match -I and -L to the prefix you installed.

7. Can I install a newer Boost without removing the apt packages?

Yes, but both trees can coexist. Headers and libraries from /usr and /usr/local compete in compiler search order—pass explicit -I/usr/local/include -L/usr/local/lib when you intend to use the source build, or uninstall libboost-all-dev to avoid accidental 1.83 linkage.

8. How do I uninstall Boost from Ubuntu?

For apt run sudo apt purge libboost-all-dev and sudo apt autoremove. For a /usr/local source install remove /usr/local/include/boost, /usr/local/lib/libboost_, and /usr/local/lib/cmake/Boost- manually or rebuild with sudo ./b2 --prefix=/usr/local uninstall if you still have the source tree.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …