How to Install Boost C++ on Ubuntu 26.04, 24.04 & 22.04

Deepak Prasad
Tested on Ubuntu 26.04 LTS (Resolute Raccoon)
Package libboost-all-dev 1.90.0.1ubuntu3 (APT Boost 1.90)
Source build: Boost 1.92.0 from archives.boost.io
g++ (Ubuntu 15.2.0-16ubuntu1)
Applies to Ubuntu 22.04 LTS, 24.04 LTS, and 26.04 LTS (Boost major differs by release)
Privilege sudo or root for apt and for installing to /usr/local
Scope Install Boost C++ libraries on Ubuntu from apt (libboost-dev, libboost-all-dev, or per-library -dev packages) or from an official source tarball when you need a newer release than the distro ships; verify with a compile test, link with g++ or CMake, and troubleshoot missing headers, linker errors, and Universe repository issues. Does not cover Conan or vcpkg as full install methods.
Related guides apt command in Linux
wget command in Linux
tar command in Linux
Check Ubuntu version
Remove software on Ubuntu
Short on time?Beta Get the gist of this 12-minute read in seconds, then ask follow-up questions

Boost is a collection of C++ libraries for tasks such as filesystem access, networking, command-line options, containers, and utilities. Some Boost libraries need compiled binaries on disk; others work entirely through header files you include in your project. On Ubuntu you normally install Boost from apt for your release, or build a specific upstream tarball from archives.boost.io when you need a newer version than the archive ships.

This guide was tested on Ubuntu 26.04 with Boost 1.90 from apt and Boost 1.92.0 from source. The same apt workflow applies on 22.04 and 24.04 with different default Boost majors (see the version table). Boost is not a standalone application—there is no general boost --version command; you verify it with dpkg, apt-cache, or a small C++ compile test. For project-level dependency pinning only, Boost also documents Conan and vcpkg on boost.org; this page covers apt and source installs on Ubuntu.


Quick answer

Ubuntu 26.04 ships Boost 1.90 in its official repositories. For the full Boost development stack:

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

If you only need one compiled component, install its development package instead—for example libboost-filesystem-dev.

At the time this guide was tested, the current upstream stable release was Boost 1.92.0. When your project requires that (or another) upstream version, build it from source under /usr/local or a user-owned prefix rather than replacing Ubuntu’s /usr packages.


Before you begin

Boost is a set of C++ headers and libraries for developers—not a program you launch after install. All commands below run on the Ubuntu machine where you compile your C++ code.

This guide uses:

  • g++ as the C++ compiler (from build-essential if it is not already installed)
  • /usr for Ubuntu-managed apt packages
  • /usr/local for a typical hand-built Boost install
  • $HOME/.local as an optional prefix that does not require sudo

Some Boost libraries are header-only: including the headers is enough. Others, such as Boost.Filesystem, also ship compiled libraries your linker must pull in with flags like -lboost_filesystem.


Boost versions on Ubuntu 26.04, 24.04 and 22.04

Source Boost version
Ubuntu 22.04 LTS 1.74
Ubuntu 24.04 LTS 1.83
Ubuntu 26.04 LTS 1.90
Upstream stable (tested tarball) 1.92.0

On Ubuntu 26.04, apt install libboost-all-dev gives you 1.90. Build 1.92.0 from source when a tutorial or upstream project names a newer Boost than apt ships.


Which Boost package should you install?

Ubuntu splits Boost into many packages. Pick the smallest install that matches your project—not every tutorial needs libboost-all-dev.

Package What it gives you Use when
libboost-dev Default Boost development headers for your Ubuntu release You mainly use header-only Boost libraries
libboost-<component>-dev Headers and compiled files for one component You know which library you link against (for example filesystem)
libboost-all-dev Metapackage that pulls most packaged Boost -dev components You want the broadest apt setup or do not know dependencies yet

Install all Boost development libraries

Install the all-in-one metapackage:

bash
sudo apt install libboost-all-dev

libboost-all-dev is a metapackage: it mainly exists to pull in many separate Boost -dev packages as dependencies rather than containing all Boost code itself. It is convenient but large (MPI and parallel graph stacks are common dependencies). Use it when you want the easiest broad setup; use narrower packages when you know your project’s dependencies.

Install the default Boost development headers

Install the default development package for your Ubuntu release:

bash
sudo apt install libboost-dev

libboost-dev is also a metapackage: it installs the default Boost development stack for your release—enough for many header-only libraries, with compiled components added via their own -dev packages when you link against them.

Install only the Boost components your project uses

Ubuntu packages each compiled Boost library separately. Install one -dev package per library you link against:

bash
sudo apt install libboost-filesystem-dev libboost-system-dev

On Ubuntu 26.04, libboost-filesystem-dev tracks Boost 1.90. Add only the libboost-<library>-dev packages your build actually needs.


Install Boost on Ubuntu with APT

Install the Boost development packages

Refresh indexes, then install the metapackage (or a narrower choice from the section above) with the apt command:

bash
sudo apt update

Install the full development stack:

bash
sudo apt install -y libboost-all-dev

On Ubuntu 26.04 the installed version was 1.90.0.1ubuntu3 (libboost-all-dev lives in the Universe component—see troubleshooting if apt cannot find the package).

Verify the installed Boost version

Boost packages supply libraries and headers; they do not always install g++. If g++ --version fails, install the toolchain first:

bash
sudo apt install -y build-essential

Confirm the package version:

bash
dpkg -s libboost-all-dev | grep -E '^Version|^Status'
output
Status: install ok installed
Version: 1.90.0.1ubuntu3

Compile a small program so you see what the compiler picks up—not only what dpkg reports:

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

Including boost/version.hpp is enough for this check—no -lboost_* linker flags yet because the version macros live in a header-only library:

bash
g++ /tmp/boost_test.cpp -o /tmp/boost_test

Run the binary:

bash
/tmp/boost_test
output
Boost version: 1.90.0

APT headers live under /usr/include/boost. On the tested x86_64 system, shared libraries such as libboost_filesystem.so are under /usr/lib/x86_64-linux-gnu/; the multiarch path differs on ARM and other architectures.


Install the latest Boost from source

When you need a source installation

Use a source build when you need an upstream release newer than apt (for example 1.92.0 on Ubuntu 26.04), custom b2 options, or a selected set of compiled libraries with specific variant / link settings.

Do not use --prefix=/usr for a hand-built Boost unless you intend to overwrite distro-managed files under /usr. Prefer /usr/local or $HOME/.local.

Install build dependencies

build-essential supplies the C++ toolchain (g++ on the tested host was 15.2.0):

bash
sudo apt install -y build-essential

Additional packages such as python3-dev, libicu-dev, zlib1g-dev, or libbz2-dev are needed only for Boost components that depend on Python, ICU, zlib, or bzip2—not for every library. Add them when b2 reports a missing dependency for the components you selected.

Download Boost 1.92.0

Pick a version from the Boost downloads page. This example uses 1.92.0 from archives.boost.io:

bash
cd /tmp

Download the tarball with wget:

bash
wget https://archives.boost.io/release/1.92.0/source/boost_1_92_0.tar.gz

Extract it (tar command options apply if you want verbose listing):

bash
tar -xf boost_1_92_0.tar.gz
cd boost_1_92_0

Bootstrap the Boost build system

bootstrap.sh prepares Boost’s B2 build system and records the install prefix. b2 is the driver that compiles the libraries you request.

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

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

When bootstrap finishes, the tree contains a b2 executable and a message that you can run ./b2 to build.

Build Boost

Build as your normal user in the extracted tree—do not run the compile phase with sudo. -j"$(nproc)" lets B2 use all CPU cores; lower the number to reduce load on shared machines.

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

A subset build on this VM took on the order of one to two minutes. A full tree without --with-* filters takes much longer and needs more disk space.

Install Boost

Install only after the build succeeds. Elevate privileges for a system prefix:

bash
sudo ./b2 \
  --with-system \
  --with-filesystem \
  variant=release \
  link=shared \
  threading=multi \
  install

Headers land under /usr/local/include/boost; libraries under /usr/local/lib.

Install Boost without sudo

To avoid writing system directories, use a user-owned prefix:

bash
./bootstrap.sh --prefix="$HOME/.local"
./b2 -j"$(nproc)" --with-filesystem variant=release link=shared threading=multi
./b2 --prefix="$HOME/.local" install

Point the compiler and CMake at that prefix with -I"$HOME/.local/include", -L"$HOME/.local/lib", or CMAKE_PREFIX_PATH.

Verify the source installation

Link against /usr/local explicitly so you do not accidentally compile against apt’s /usr/include/boost:

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

Compile and link. Boost.Filesystem needs a compiled library; -I adds a header search path, -L adds a library search path, and -lboost_filesystem tells the linker to use Boost.Filesystem:

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

For this test, tell the dynamic linker where the /usr/local libraries are for one command only:

bash
LD_LIBRARY_PATH=/usr/local/lib /tmp/boost_local_test

LD_LIBRARY_PATH applies only to that invocation—it does not change system-wide linker settings.

output
Boost version: 1.92.0
exists /tmp: 1

LD_LIBRARY_PATH makes this test explicit. After a /usr/local install, refresh the dynamic linker cache when needed:

bash
sudo ldconfig
ldconfig -p | grep boost_filesystem

If you skip ldconfig, you may still need LD_LIBRARY_PATH (or an rpath) when you run binaries linked against /usr/local/lib.


Use Boost in a C++ project

Compile with g++

With apt Boost and a program that uses Boost.Filesystem:

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

Add other -lboost_<component> flags for each compiled library you use.

Use Boost with CMake

If CMake is not installed yet, run sudo apt install cmake. find_package() locates the installed Boost package; Boost::filesystem is the CMake target that carries the right include and link settings for that component.

APT Boost on Ubuntu 26.04 (example requires filesystem):

cmake
cmake_minimum_required(VERSION 3.16)
project(demo CXX)
find_package(Boost 1.90 REQUIRED COMPONENTS filesystem)
add_executable(demo main.cpp)
target_link_libraries(demo Boost::filesystem)

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.92 REQUIRED COMPONENTS filesystem)
add_executable(demo main.cpp)
target_link_libraries(demo Boost::filesystem)

Uninstall Boost

APT packages and hand-built trees uninstall differently. Pick the subsection that matches how you installed Boost.

Remove Ubuntu packages

Purge the metapackage, then autoremove packages that are no longer required:

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

Remove narrower libboost-*-dev packages if you installed them instead of the metapackage.

Remove a source installation

WARNING
These commands remove Boost files under the chosen prefix. Use them only when /usr/local (or your prefix) holds the source build you intend to delete. They also remove another manually installed Boost tree that shares the same paths.

For /usr/local:

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

See how to remove software on Ubuntu for broader cleanup patterns.


Troubleshooting

Unable to locate package libboost-all-dev

libboost-all-dev is provided through Ubuntu’s Universe component rather than Main. Enable Universe and refresh indexes:

bash
sudo add-apt-repository universe
sudo apt update
sudo apt install libboost-all-dev

If add-apt-repository is not found, install software-properties-common first, then rerun the commands above.

fatal error: boost/...: No such file or directory

The compiler cannot find Boost headers. Typical locations:

  • APT: /usr/include/boost/
  • Source install with --prefix=/usr/local: /usr/local/include/boost/
  • Custom prefix: add -I/path/to/include to g++ or set CMAKE_PREFIX_PATH for CMake.

Install libboost-all-dev or the specific libboost-<library>-dev package before you add manual -I paths.

undefined reference to boost::...

You included headers but did not link the compiled Boost library. Add the matching -lboost_<component> flag (for example -lboost_filesystem) or use CMake imported targets such as Boost::filesystem.

CMake reports Could NOT find Boost

Common causes:

  • A required component package is not installed (libboost-filesystem-dev, and so on).
  • CMake is picking up apt Boost while you built a newer tree under /usr/local (set CMAKE_PREFIX_PATH).
  • Headers from one Boost version and libraries from another are mixed—make sure the compiler and CMake both point to the same Boost installation (-I/-L or CMAKE_PREFIX_PATH).

Compiler uses the wrong Boost version

If both /usr/include/boost and /usr/local/include/boost exist, g++ may prefer /usr unless you pass -I/usr/local/include -L/usr/local/lib (or uninstall the apt dev packages you do not want in the search path). Always confirm with a small program that prints BOOST_VERSION from the headers you intend to use.

Symptom Likely cause Fix
g++: command not found C++ compiler not installed sudo apt install build-essential
b2 install fails on common.mkdir /usr/local/... Install step run without permission to the prefix Use sudo only for b2 install, or --prefix=$HOME/.local without sudo
Old JFrog download URL fails Legacy redirect Use https://archives.boost.io/release/<ver>/source/boost_<ver>_0.tar.gz
Full b2 build runs for hours Building every library Use --with-<library> during development

Summary

On Ubuntu 26.04, sudo apt install libboost-all-dev installs Boost 1.90 with headers under /usr/include/boost—the right default for most C++ work on that release. When a project needs 1.92.0 (or another upstream version), download the tarball from archives.boost.io, run ./bootstrap.sh --prefix=/usr/local, build with ./b2 as your user, and run sudo ./b2 install only for the install step.

Verify any install path by compiling code that includes boost/version.hpp and, for compiled libraries, linking the matching -lboost_* component. Keep apt Boost under /usr and source Boost under /usr/local (or $HOME/.local) unless you are deliberately managing a single prefix—mixing trees without -I, -L, or CMAKE_PREFIX_PATH is the usual reason the compiler reports the wrong version.


References


Frequently Asked Questions

Which Boost version does Ubuntu 26.04 include?

Ubuntu 26.04 provides Boost 1.90 through packages such as libboost-all-dev (version 1.90.0.1ubuntu3 on the tested system). Run apt-cache policy libboost-all-dev or compile a program that prints BOOST_VERSION to confirm.

Should I install libboost-dev or libboost-all-dev?

Use libboost-all-dev when you want every Boost development package Ubuntu splits out in one step. Use libboost-dev plus individual libboost-<library>-dev packages when you want a smaller install. Many tutorials mention only libboost-all-dev because it is the fastest way to satisfy unknown dependencies.

How do I install the latest Boost on Ubuntu?

Install the newest upstream release from archives.boost.io with ./bootstrap.sh, ./b2, and b2 install to your chosen prefix. Ubuntu’s apt version and the upstream tarball version are independent—26.04 apt stays on 1.90 while upstream may be 1.92.0 or newer.

Can APT Boost and a source build coexist?

Yes, but both can appear on disk at once (/usr and /usr/local). Pass explicit include and library paths—or CMAKE_PREFIX_PATH—so your project uses the tree you intend. Remove or avoid apt dev packages if you want source Boost to be the only visible install.

Why does apt say it cannot find libboost-all-dev?

Enable the Universe component with sudo add-apt-repository universe, run sudo apt update, then install again. libboost-all-dev is provided through Universe rather than the Main repository on current Ubuntu releases.

Finished reading?Beta Get the key takeaways in seconds, then ask follow-up questions
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware.

  • Debian
  • Ubuntu
  • Linux
  • Red Hat Enterprise Linux
  • Shell Script
  • System Administration