| 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 |
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:
sudo apt update
sudo apt install libboost-all-devIf 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 (frombuild-essentialif it is not already installed)/usrfor Ubuntu-managed apt packages/usr/localfor a typical hand-built Boost install$HOME/.localas an optional prefix that does not requiresudo
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:
sudo apt install libboost-all-devlibboost-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:
sudo apt install libboost-devlibboost-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:
sudo apt install libboost-filesystem-dev libboost-system-devOn 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:
sudo apt updateInstall the full development stack:
sudo apt install -y libboost-all-devOn 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:
sudo apt install -y build-essentialConfirm the package version:
dpkg -s libboost-all-dev | grep -E '^Version|^Status'Status: install ok installed
Version: 1.90.0.1ubuntu3Compile a small program so you see what the compiler picks up—not only what dpkg reports:
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;
}
EOFIncluding boost/version.hpp is enough for this check—no -lboost_* linker flags yet because the version macros live in a header-only library:
g++ /tmp/boost_test.cpp -o /tmp/boost_testRun the binary:
/tmp/boost_testBoost version: 1.90.0APT 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):
sudo apt install -y build-essentialAdditional 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:
cd /tmpDownload the tarball with wget:
wget https://archives.boost.io/release/1.92.0/source/boost_1_92_0.tar.gzExtract it (tar command options apply if you want verbose listing):
tar -xf boost_1_92_0.tar.gz
cd boost_1_92_0Bootstrap 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:
./bootstrap.sh --prefix=/usr/localWhen 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.
./b2 -j"$(nproc)" \
--with-system \
--with-filesystem \
variant=release \
link=shared \
threading=multiA 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:
sudo ./b2 \
--with-system \
--with-filesystem \
variant=release \
link=shared \
threading=multi \
installHeaders 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:
./bootstrap.sh --prefix="$HOME/.local"
./b2 -j"$(nproc)" --with-filesystem variant=release link=shared threading=multi
./b2 --prefix="$HOME/.local" installPoint 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:
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;
}
EOFCompile 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:
g++ /tmp/boost_local_test.cpp -o /tmp/boost_local_test \
-I/usr/local/include -L/usr/local/lib -lboost_filesystemFor this test, tell the dynamic linker where the /usr/local libraries are for one command only:
LD_LIBRARY_PATH=/usr/local/lib /tmp/boost_local_testLD_LIBRARY_PATH applies only to that invocation—it does not change system-wide linker settings.
Boost version: 1.92.0
exists /tmp: 1LD_LIBRARY_PATH makes this test explicit. After a /usr/local install, refresh the dynamic linker cache when needed:
sudo ldconfig
ldconfig -p | grep boost_filesystemIf 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:
g++ main.cpp -o app -lboost_filesystemAdd 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_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_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:
sudo apt purge -y libboost-all-dev
sudo apt autoremove -yRemove narrower libboost-*-dev packages if you installed them instead of the metapackage.
Remove a source installation
/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:
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:
sudo add-apt-repository universe
sudo apt update
sudo apt install libboost-all-devIf 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/includetog++or setCMAKE_PREFIX_PATHfor 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(setCMAKE_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/-LorCMAKE_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
- Boost C++ Libraries — downloads
- Boost getting started on Unix variants
- archives.boost.io — official release tarballs
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.

