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.
./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
/usror/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.comandarchives.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:
sudo apt update
sudo apt install -y libboost-all-devOn Ubuntu 25.04 the candidate before install was 1.83.0.2ubuntu1. The tail of apt install finished with:
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:
dpkg -s libboost-all-dev | grep -E '^Version|^Status'
ls /usr/lib/x86_64-linux-gnu/libboost_system.so*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.0libboost-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:
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_testBoost version: 1.83.0boost/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:
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_0The 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:
sudo apt install -y build-essential g++ python3-dev libicu-dev libbz2-devOn 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:
./bootstrap.sh --prefix=/usr/localNear the end of bootstrap:
Generating B2 configuration in project-config.jam for gcc...
Bootstrapping is done. To build, run:
./b2
To generate header files, run:
./b2 headersBootstrap 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-*:
sudo ./b2 -j"$(nproc)" \
--with-system \
--with-filesystem \
variant=release \
link=shared \
threading=multi \
installWithout 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:
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:
ls -la /usr/local/lib/libboost_system.so* /usr/local/lib/libboost_filesystem.so*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.0To install everything, drop the --with-* filters and budget substantially more time and CPU:
sudo ./b2 -j"$(nproc)" variant=release link=shared threading=multi install--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:
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_testBoost version: 1.87.0
exists /tmp: 1If 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):
g++ main.cpp -o app -lboost_filesystem -lboost_systemCMake (source install under /usr/local):
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:
sudo apt purge -y libboost-all-dev
sudo apt autoremove -ySource install under /usr/local (adjust if you used another prefix):
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
- Boost downloads — release index and version notes
- Boost getting started on Unix — official
bootstrap.sh/b2flow - archives.boost.io — current tarball host used in this guide
- Stack Overflow: How to install Boost on Ubuntu
- Baeldung: Boost install on Ubuntu
- On-site: wget command, tar command, install GCC on Rocky Linux (toolchain context for C++ builds)
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.

