How to Install Boost on Ubuntu 16.04/18.04 Linux

This post will guide you how to install Boost libraries on Ubunt 16.04/18.04 Linux server. How do I install Boost C++ libraries 1.64 from a PPA in Ubuntu. How to install Boost from the default repositories on Ubuntu 16.04/18.04 Linux. How to install the latest version of Boost libraries from source package on Ubuntu Linux server.

What is Boost?


Boost is a set of libraries for the C++ programming language that provide support for tasks and structures such as linear algebra, pseudorandom number generation, multithreading, image processing, regular expressions, and unit testing. It contains over eighty individual libraries.

Install Boost C++ libraries via Default Repository


Boost is available on the default Ubuntu repositories, so you can install it with apt command directly, type the following commmand:

$ sudo apt install libboost-dev
$ sudo apt install libboost-all-dev

Outputs:

devops@devops-osetc:~$ sudo apt install libboost-dev
[sudo] password for devops:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libllvm6.0 x11proto-dri2-dev x11proto-gl-dev
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libboost1.65-dev
Suggested packages:
libboost-doc libboost1.65-doc libboost-atomic1.65-dev libboost-chrono1.65-dev libboost-container1.65-dev libboost-context1.65-dev
libboost-coroutine1.65-dev libboost-date-time1.65-dev libboost-exception1.65-dev libboost-fiber1.65-dev libboost-filesystem1.65-dev
libboost-graph1.65-dev libboost-graph-parallel1.65-dev libboost-iostreams1.65-dev libboost-locale1.65-dev libboost-log1.65-dev libboost-math1.65-dev
libboost-mpi1.65-dev libboost-mpi-python1.65-dev libboost-numpy1.65-dev libboost-program-options1.65-dev libboost-python1.65-dev
libboost-random1.65-dev libboost-regex1.65-dev libboost-serialization1.65-dev libboost-signals1.65-dev libboost-stacktrace1.65-dev
libboost-system1.65-dev libboost-test1.65-dev libboost-thread1.65-dev libboost-timer1.65-dev libboost-type-erasure1.65-dev libboost-wave1.65-dev
libboost1.65-tools-dev libmpfrc++-dev libntl-dev
The following NEW packages will be installed:
libboost-dev libboost1.65-dev
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 7,221 kB of archives.
After this operation, 119 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://mirrors.aliyun.com/ubuntu bionic/main amd64 libboost1.65-dev amd64 1.65.1+dfsg-0ubuntu5 [7,218 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic/main amd64 libboost-dev amd64 1.65.1.0ubuntu1 [3,128 B]
Fetched 7,221 kB in 4s (1,944 kB/s)
Selecting previously unselected package libboost1.65-dev:amd64.
(Reading database ... 214899 files and directories currently installed.)
Preparing to unpack .../libboost1.65-dev_1.65.1+dfsg-0ubuntu5_amd64.deb ...
Unpacking libboost1.65-dev:amd64 (1.65.1+dfsg-0ubuntu5) ...
Selecting previously unselected package libboost-dev:amd64.
Preparing to unpack .../libboost-dev_1.65.1.0ubuntu1_amd64.deb ...
Unpacking libboost-dev:amd64 (1.65.1.0ubuntu1) ...
Setting up libboost1.65-dev:amd64 (1.65.1+dfsg-0ubuntu5) ...
Setting up libboost-dev:amd64 (1.65.1.0ubuntu1) ...

devops@devops-osetc:~$ sudo apt install libboost-all-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libllvm6.0 x11proto-dri2-dev x11proto-gl-dev
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
gir1.2-harfbuzz-0.0 icu-devtools libboost-atomic-dev libboost-atomic1.65-dev libboost-atomic1.65.1 libboost-chrono-dev libboost-chrono1.65-dev
0 upgraded, 122 newly installed, 0 to remove and 0 not upgraded.
Need to get 68.6 MB of archives.
After this operation, 214 MB of additional disk space will be used.
Do you want to continue? [Y/n]
......
Setting up mpi-default-bin (1.10) ...
Setting up libboost-graph-parallel1.65.1 (1.65.1+dfsg-0ubuntu5) ...
Setting up libboost-thread-dev:amd64 (1.65.1.0ubuntu1) ...
Setting up libboost-graph-parallel1.65-dev (1.65.1+dfsg-0ubuntu5) ...
Setting up libboost-timer-dev:amd64 (1.65.1.0ubuntu1) ...
Setting up libboost-log1.65-dev (1.65.1+dfsg-0ubuntu5) ...
Setting up libboost-graph-parallel-dev (1.65.1.0ubuntu1) ...
Setting up libboost-mpi-dev (1.65.1.0ubuntu1) ...
Setting up libboost-mpi-python1.65.1 (1.65.1+dfsg-0ubuntu5) ...
Setting up libboost-mpi-python1.65-dev (1.65.1+dfsg-0ubuntu5) ...
Setting up libboost-log-dev (1.65.1.0ubuntu1) ...
Setting up libboost-mpi-python-dev (1.65.1.0ubuntu1) ...
Setting up libharfbuzz-dev:amd64 (1.7.2-1ubuntu1) ...
Setting up libicu-le-hb-dev:amd64 (1.0.3+git161113-4) ...
Setting up libicu-dev (60.2-3ubuntu3) ...
Setting up libboost-regex1.65-dev:amd64 (1.65.1+dfsg-0ubuntu5) ...
Setting up libboost-iostreams1.65-dev:amd64 (1.65.1+dfsg-0ubuntu5) ...
Setting up libboost-iostreams-dev:amd64 (1.65.1.0ubuntu1) ...
Setting up libboost-regex-dev:amd64 (1.65.1.0ubuntu1) ...
Setting up libboost-all-dev (1.65.1.0ubuntu1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

Verify the installed Boost Version

Once completed the installation process of Boost on your Ubuntu server, you can verify the installed boost version to check if the Boost is installed properly. Type one of the following commands to check version of boost:

$ dpkg -s libboost-dev | grep Version

Or

$ cat /usr/include/boost/version.hpp | grep "BOOST_LIB_VERSION"

Outputs:

devops@devops-osetc:~$ dpkg -s libboost-dev | grep version
Description: Boost C++ Libraries development files (default version)
Boost version (currently 1.65).

devops@devops-osetc:~$ cat /usr/include/boost/version.hpp | grep "BOOST_LIB_VERSION"
// BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
#define BOOST_LIB_VERSION "1_65_1"

Install Boost C++ libraries From PPA


You can also install Boost from a PPA on Ubuntu Linux, just type the following command:

$ sudo add-apt-repository ppa:mhier/libboost-latest
$ sudo apt update

This PPA can be added to your system manually by copying the lines below and adding them to your system’s software sources.

For Ubuntu 18.04:

deb http://ppa.launchpad.net/mhier/libboost-latest/ubuntu bionic main
deb-src http://ppa.launchpad.net/mhier/libboost-latest/ubuntu bionic main

For Ubuntu 18.10:

deb http://ppa.launchpad.net/mhier/libboost-latest/ubuntu cosmic main
deb-src http://ppa.launchpad.net/mhier/libboost-latest/ubuntu cosmic main

For Ubuntu 16.04:

deb http://ppa.launchpad.net/mhier/libboost-latest/ubuntu xenial main
deb-src http://ppa.launchpad.net/mhier/libboost-latest/ubuntu xenial main

Then you can try to install the Boost on your Ubuntu Linux, and the latest version of this PPA is 1.68, type the following command to install it:

$ sudo apt install libboost

Then the latest version 1.68 of boost would be installed on your Ubuntu Linux server.

Install Boost C++ libraries From Source Package


If you want to install the latest version of Boost( the current release version is 1.69) on your Ubuntu server, you have to install it from source package. And you need to download the latest archive package of boost from its official site firstly. . then execute the installation script. Just do the following steps:

#1 download source package of boost from this link with wget tool, type:

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

Outputs:

devops@devops-osetc:~$ wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
--2019-01-01 08:04:23-- https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
Resolving www-proxy.us.osetc.com (www-proxy.us.osetc.com)... 148.87.19.20
Connecting to www-proxy.us.osetc.com (www-proxy.us.osetc.com)|148.87.19.20|:80... connected.
Proxy request sent, awaiting response... 302
Location: https://d29vzk4ow07wi7.cloudfront.net/9a2c2819310839ea373f42d69e733c339b4e9a19deab6bfec448281554aa4dbb?response-content-disposition=attachment%3Bfilename%3D%22boost_1_69_0.tar.gz%22&Policy=eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dHAqOi8vZDI5dnprNG93MDd3aTcuY2xvdWRmcm9udC5uZXQvOWEyYzI4MTkzMTA4MzllYTM3M2Y0MmQ2OWU3MzNjMzM5YjRlOWExOWRlYWI2YmZlYzQ0ODI4MTU1NGFhNGRiYj9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPWF0dGFjaG1lbnQlM0JmaWxlbmFtZSUzRCUyMmJvb3N0XzFfNjlfMC50YXIuZ3olMjIiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE1NTAxOTg3NjF9LCJJcEFkZHJlc3MiOnsiQVdTOlNvdXJjZUlwIjoiMC4wLjAuMC8wIn19fV19&Signature=B9510Igr-VQqH3t7bBFKuS~4mS921yfXcBgGhUE1ZYgLi1JUOV~eJMDFFjfiS3QPejCBkHtH7ztuSENg19D4cVNve0I4rIQ3lQfVY~bV4M064eYpZyJBJFiBWsWXpZLwciYQ-xbx7KpPbKEezaSNA1xGB8QrGDrbMVpPTRYCBloPgKBX7BYkeT5iH0LtvJ4qXBjcGOWYELUSqMHZbPPclIb6IudXpHhITOiSwwqpZB--4SGAl681S5aBjyVViydBznnawrIOiK67Mpk7-eEtNMyNA1DD7SNbiyL6feAayWOZ08LoyLEbkEDjED5aSSkrN5dPsHj0nnN6wDjEuN~X2g__&Key-Pair-Id=APKAIFKFWOMXM2UMTSFA [following]
--2019-01-01 08:04:24-- https://d29vzk4ow07wi7.cloudfront.net/9a2c2819310839ea373f42d69e733c339b4e9a19deab6bfec448281554aa4dbb?response-content-disposition=attachment%3Bfilename%3D%22boost_1_69_0.tar.gz%22&Policy=eyJTdGF0ZW1lbnQiOiBbeyJSZXNvdXJjZSI6Imh0dHAqOi8vZDI5dnprNG93MDd3aTcuY2xvdWRmcm9udC5uZXQvOWEyYzI4MTkzMTA4MzllYTM3M2Y0MmQ2OWU3MzNjMzM5YjRlOWExOWRlYWI2YmZlYzQ0ODI4MTU1NGFhNGRiYj9yZXNwb25zZS1jb250ZW50LWRpc3Bvc2l0aW9uPWF0dGFjaG1lbnQlM0JmaWxlbmFtZSUzRCUyMmJvb3N0XzFfNjlfMC50YXIuZ3olMjIiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE1NTAxOTg3NjF9LCJJcEFkZHJlc3MiOnsiQVdTOlNvdXJjZUlwIjoiMC4wLjAuMC8wIn19fV19&Signature=B9510Igr-VQqH3t7bBFKuS~4mS921yfXcBgGhUE1ZYgLi1JUOV~eJMDFFjfiS3QPejCBkHtH7ztuSENg19D4cVNve0I4rIQ3lQfVY~bV4M064eYpZyJBJFiBWsWXpZLwciYQ-xbx7KpPbKEezaSNA1xGB8QrGDrbMVpPTRYCBloPgKBX7BYkeT5iH0LtvJ4qXBjcGOWYELUSqMHZbPPclIb6IudXpHhITOiSwwqpZB--4SGAl681S5aBjyVViydBznnawrIOiK67Mpk7-eEtNMyNA1DD7SNbiyL6feAayWOZ08LoyLEbkEDjED5aSSkrN5dPsHj0nnN6wDjEuN~X2g__&Key-Pair-Id=APKAIFKFWOMXM2UMTSFA
Connecting to www-proxy.us.osetc.com (www-proxy.us.osetc.com)|148.87.19.20|:80... connected.
Proxy request sent, awaiting response... 200 OK
Length: 111710205 (107M) [application/gzip]
Saving to: ‘boost_1_69_0.tar.gz’

boost_1_69_0.tar.gz 100%[==========================================================================>] 106.53M 344KB/s in 5m 19s

2019-01-01 08:09:45 (342 KB/s) - ‘boost_1_69_0.tar.gz’ saved [111710205/111710205]

#2 extract all files from the archive file that you downloaded in the above step. type:

$ tar -zxvf boost_1_69_0.tar.gz

Outputs:

devops@devops-osetc:~$ tar -zxvf boost_1_69_0.tar.gz

......
boost_1_69_0/tools/quickbook/test/utf8_bom-1_5.gold
boost_1_69_0/tools/quickbook/test/utf8_bom-1_5.gold-html
boost_1_69_0/tools/quickbook/test/utf8_bom-1_5.quickbook
boost_1_69_0/tools/quickbook/test/variablelist-1_5-fail.quickbook
boost_1_69_0/tools/quickbook/test/variablelist-1_5.gold
boost_1_69_0/tools/quickbook/test/variablelist-1_5.gold-html
boost_1_69_0/tools/quickbook/test/variablelist-1_5.quickbook
boost_1_69_0/tools/quickbook/test/version-0_1-fail.quickbook
boost_1_69_0/tools/quickbook/test/version-1_8-fail.quickbook
boost_1_69_0/tools/quickbook/test/version-2_0-fail.quickbook
boost_1_69_0/tools/quickbook/test/xml_escape-1_2.gold
boost_1_69_0/tools/quickbook/test/xml_escape-1_2.gold-html
boost_1_69_0/tools/quickbook/test/xml_escape-1_2.quickbook
boost_1_69_0/tools/quickbook/test/xml_escape-1_5.gold
boost_1_69_0/tools/quickbook/test/xml_escape-1_5.gold-html
boost_1_69_0/tools/quickbook/test/xml_escape-1_5.quickbook
boost_1_69_0/tools/quickbook/Jamfile.v2
boost_1_69_0/tools/quickbook/_clang-format
boost_1_69_0/tools/quickbook/index.html
boost_1_69_0/tools/Jamfile.v2
boost_1_69_0/tools/index.html
boost_1_69_0/tools/make-cputime-page.pl

#3 Change the current directory to boost_1_69_0/, type:

$ cd boost_1_69_0/

#4 execute the script bootstrap.sh, type the following command:

$ ./bootstrap.sh

Outputs:

devops@devops-osetc:~/boost_1_69_0$ ./bootstrap.sh
Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.7
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... /usr
Generating Boost.Build configuration in project-config.jam...

Bootstrapping is done. To build, run:

./b2

To adjust configuration, edit 'project-config.jam'.
Further information:

- Command line help:
./b2 --help

- Getting started guide:
http://www.boost.org/more/getting_started/unix-variants.html

- Boost.Build documentation:
http://www.boost.org/build/doc/html/index.html

#5 Builds and installs Boost with the following command:

$ ./b2

Outputs:

devops@devops-osetc:~/boost_1_69_0$ ./b2
Performing configuration checks

- default address-model : 64-bit
- default architecture : x86

Building the Boost C++ Libraries.

- C++11 mutex : yes
- lockfree boost::atomic_flag : yes
- Boost.Config Feature Check: cxx11_auto_declarations : yes
- Boost.Config Feature Check: cxx11_constexpr : yes
- Boost.Config Feature Check: cxx11_defaulted_functions : yes
- Boost.Config Feature Check: cxx11_final : yes
- Boost.Config Feature Check: cxx11_hdr_mutex : yes
- Boost.Config Feature Check: cxx11_hdr_tuple : yes
- Boost.Config Feature Check: cxx11_lambdas : yes
- Boost.Config Feature Check: cxx11_noexcept : yes
- Boost.Config Feature Check: cxx11_nullptr : yes
- Boost.Config Feature Check: cxx11_rvalue_references : yes
- Boost.Config Feature Check: cxx11_template_aliases : yes
- Boost.Config Feature Check: cxx11_thread_local : yes
- Boost.Config Feature Check: cxx11_variadic_templates : yes
- has_icu builds : yes
warning: Graph library does not contain MPI-based parallel components.
note: to enable them, add "using mpi ;" to your user-config.jam
- zlib : yes
- bzip2 : no
- lzma : no
- zstd : no
- iconv (libc) : yes
- icu : yes
warning: non-free usage requirements <runtime-link>shared ignored
warning: in main-target build_options at libs/locale/build/Jamfile.v2:414
warning: non-free usage requirements <runtime-link>shared ignored
warning: in main-target build_flags at libs/locale/build/Jamfile.v2:415
- native-atomic-int32-supported : yes
- native-syslog-supported : yes
- pthread-supports-robust-mutexes : yes
- compiler-supports-ssse3 : yes
- compiler-supports-avx2 : yes
- gcc visibility : yes
- long double support : yes
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
- libbacktrace builds : yes
- addr2line builds : yes
- WinDbg builds : no
- WinDbgCached builds : no
- BOOST_COMP_GNUC >= 4.3.0 : yes
- zlib : yes
- bzip2 : no
- lzma : no
- zstd : no

Component configuration:

- atomic : building
- chrono : building
- container : building
- context : building
- contract : building
- coroutine : building
- date_time : building
- exception : building
- fiber : building
- filesystem : building
- graph : building
- graph_parallel : building
- iostreams : building
- locale : building
- log : building
- math : building
- mpi : building
- program_options : building
- python : building
- random : building
- regex : building
- serialization : building
- stacktrace : building
- system : building
- test : building
- thread : building
- timer : building
- type_erasure : building
- wave : building

...patience...
...found 14633 targets...
...updating 1330 targets...
gcc.compile.c++.pch bin.v2/libs/math/build/gcc-7.3.0/release/link-static/threading-multi/visibility-hidden/../src/tr1/pch.hpp.gch

Conclusion


You should know that how to install Boost C++ Libraries on your Ubuntu 16.04 or 18.04 Linux from this guide. And if you want to learn more about the Boost, you can go the below official web site to checking the getting started guide directly.

You might also like:

Sidebar



back to top