How to install Boost on Ubuntu
Asked Answered
T

10

658

I'm on Ubuntu, and I want to install Boost. I tried with

sudo apt-get install boost

But there was no such package. What is the best way to install Boost on Ubuntu?

Taipan answered 25/9, 2012 at 7:52 Comment(0)
C
1134

You can use apt-get command (requires sudo)

sudo apt-get install libboost-all-dev

Or you can call

aptitude search boost

find packages you need and install them using the apt-get command.

Choriocarcinoma answered 25/9, 2012 at 7:57 Comment(12)
do you have any past experience with boost?Taipan
I had programming experience with boost, but not installation experience. I have never tried this myself, so I can't say if it is easy to use (but it seems to me that package manager is the easiest way). I should have posted this suggestion as a comment, but I can't comment questions.Choriocarcinoma
You can try this link, but I think there should not be any problem, you just install with aptitude and then start using boostChoriocarcinoma
The one disadvantage of using apt-get is that it is usually a couple of version behind the latest boost release.Batory
can you suggest another way by which the "" mismatched versions of Boost.Build engine and core"" can be sorted out?Taipan
It is easy to build and install Boost from the sources, for example anycoder.wordpress.com/2014/04/28/building-boostO
Great it worked like a charm, is there any way to install specific package of boost, for example I want to install only boost/asio.h and its dependencies, is there any way to achieve thatClingy
I had that and still get .build_release/lib/libcaffe.so: undefined reference to `boost::python::throw_error_already_set()'Au
I think have to mention that to install a particular library you need to enter the following command: aptitude install libboost_library_namePresbyterian
It seems it doesn't work - I ran the command sudo apt-get install libboost-filesystem1.55.0, but only libraries are installed, not headers. #include <boost/filesystem.hpp> or #include <boost/filesystem> complains about missing file.Navy
Do not use the packaged version of boost, right now on Ubuntu 16.04 it's 1.58, and the latest stable version is 1.67.0 ! See the response and my comment below : https://mcmap.net/q/63784/-how-to-install-boost-on-ubuntuPolyvalent
plz keep in mind this will install ALL packages in boost, something like 8 upgraded, 274 newly installed, Need to get 192 MB of archives. After this operation, 724 MB of additional disk space will be used., you can install only needed onesIble
O
261

Get the version of Boost that you require. This is for 1.55 but feel free to change or manually download yourself:

wget -O boost_1_55_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download
tar xzvf boost_1_55_0.tar.gz
cd boost_1_55_0/

Get the required libraries, main ones are icu for boost::regex support:

sudo apt-get update
sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev libboost-all-dev

Boost's bootstrap setup:

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

Then build it with:

./b2

and eventually install it:

sudo ./b2 install
Octofoil answered 6/6, 2014 at 16:14 Comment(12)
What will be the difference if we use ./bootstrap.sh --prefix=/usr/include ? I have the boost library in /usr/include. I was wondering that by doing this, can I replace my old installation ?Roose
what is libboost-all-dev ? why should I install boost before installing boost?Cigar
@tbc0 Boost is at version 1.59 now, and the latest PPA is at 1.55, so building from source is relevantBookshelf
building from source is a great exercise anyways, there's no harm if they're interested in trying, and as the top answer here already showed how to use the package manager, it's nice to have another answer show an alternative method.Parian
How do we verify the version to ensure it installed correctly at the end? I just compiled & did ./b2 install on Boost v1.66.0 but running dpkg -s libboost-dev | grep 'Version' says I have version 1.54.0.1ubuntu1--probably because that's what was previously installed via sudo apt install libboost-all-devGisela
@javapowered If some program will try to install some boost headers/files, it will override lastest ones and create hell.Valona
sudo ./b2 install builds it as well. You don't have to call ./b2 beforehand.Biltong
this is nice but it screws up cmakeJury
@BenB To install somewhere else. Also, consider using the --show-libraries and --with-libraries=library-name-list options to limit the long wait you'll experience if you build everything. Finally.Usually
Thanks for sharing the installation step. Where do you find these in the Boost website?Judaism
worked for me on my Ubuntu 18.04Scoria
It worked for me, thanks. But now I need to uninstall it again to test something with the default boost for my system. I tried sudo ./b2 install and sudo ./b2 remove without success. Is there a b2 target for uninstalling?Chiefly
C
104

Installing Boost on Ubuntu with an example of using boost::array:

Install libboost-all-dev and aptitude:

sudo apt install libboost-all-dev

sudo apt install aptitude

aptitude search boost

Then paste this into a C++ file called main.cpp:

#include <iostream>
#include <boost/array.hpp>

using namespace std;
int main(){
  boost::array<int, 4> arr = {{1,2,3,4}};
  cout << "hi" << arr[0];
  return 0;
}

Compile like this:

g++ -o s main.cpp

Run it like this:

./s

Program prints:

hi1
Cabrera answered 15/5, 2014 at 2:36 Comment(3)
There is an error in the line "boost::array<int, 4> arr = {{1,2,3,4}};", it should be "boost::array<int, 4> arr = {1,2,3,4};"Cunningham
why do i want to run aptitude search boost?Navy
adding "<< endl;" to the"cout" line was required to flush the buffer and make my output show when running in a terminal.Figurate
P
37

Get the version of Boost that you require. This is for 1.55 but feel free to change or manually download yourself (Boost download page):

wget -O boost_1_55_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download
tar xzvf boost_1_55_0.tar.gz
cd boost_1_55_0/

Get the required libraries, main ones are icu for boost::regex support:

sudo apt-get update
sudo apt-get install build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev 

Boost's bootstrap setup:

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

If we want MPI then we need to set the flag in the user-config.jam file:

user_configFile=`find $PWD -name user-config.jam`
echo "using mpi ;" >> $user_configFile

Find the maximum number of physical cores:

n=`cat /proc/cpuinfo | grep "cpu cores" | uniq | awk '{print $NF}'`

Install boost in parallel:

sudo ./b2 --with=all -j $n install 

Assumes you have /usr/local/lib setup already. if not, you can add it to your LD LIBRARY PATH:

sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/local.conf'

Reset the ldconfig:

sudo ldconfig
Putupon answered 21/12, 2016 at 22:13 Comment(6)
Some things such as PO Edit 2.0 require boost 1.6, which is not available at this time via apt-get you can get this from boost.org/users/history/version_1_60_0.html and then expand it. Follow the excellent instructions above, remembering that LD Library Path is not the same as $PATHAdlei
Please change the link to HTTPS; HTTP isn't safe for binary downloads :)Hoboken
Comment from a recent installation, to get the latest version : - Go to boost.org and "Current release" downloads to get the last one (currently 1.67.0 : dl.bintray.com/boostorg/release/1.67.0/source/…) Thanks !Polyvalent
haha this screws up my system for good. i think it's the last 2 items.Jury
old link to sourceforge is not working. use dl.bintray.com/boostorg/release/1.72.0/source/… (with needed version)Hexaemeron
That helped me with adding Boost 1.74.0 for including boost/math/interpolators/catmull_rom.hpp to ROS Melodic. I get a ton of deprecated messages from ROS headers, but it works for what I need. Thanks!Temperance
M
23

An update for Windows 10 Ubuntu Application via Subsystem (also works on standard Ubuntu):

You might have problems finding the package. If you do, never fear! PPA is here!

sudo add-apt-repository ppa:boost-latest/ppa
sudo apt-get update

Then run:

sudo apt-get install libboost-all-dev
Matrilateral answered 14/6, 2018 at 21:49 Comment(6)
OP didn't ask for Win10.Mansuetude
I'm aware, posting for those (Like me) who were looking for a rounded solution. Similar to Алексей Штыков's AnswerMatrilateral
@AdrianW this answer isn't about Windows 10. It's about Ubuntu that happens to be running on a Windows 10 kernel, so it's a valid solution to those running Ubuntu in some way. Since the question didn't limit it to Ubuntu running on a Linux kernel specifically, this solution is fine.Viator
The repository 'ppa.launchpad.net/boost-latest/ppa/ubuntu xenial Release' does not have a Release file.Quilt
Not to necro, but another point was brought up in another solution, which being that Packaged versions can be dated compared to source-compiled versions. If you use my solution, I'd follow the same advice which is to check if the version packaged fits your needs/enviroment.Matrilateral
I am having following erro: E: The repository 'http://ppa.launchpad.net/boost-latest/ppa/ubuntu focal Release' does not have a Release file.Evocation
T
12

You can install boost on ubuntu by using the following commands:

sudo apt update

sudo apt install libboost-all-dev

Touchandgo answered 1/11, 2020 at 11:37 Comment(0)
A
10

First try the following:

$ sudo apt-get install libboost*

You may get an error message similar to the following, like I did:

E: Unable to correct problems, you have held broken packages.

Then try install below package:

$ sudo apt-get install libboost-all-dev

Now you can create a a sample project utilizing Boost:

$ mkdir boost
$ cd boost/
$ cat > main.cpp &
Accentuate answered 6/9, 2021 at 21:10 Comment(0)
E
3

Actually you don't need "install" or "compile" anything before using Boost in your project. You can just download and extract the Boost library to any location on your machine, which is usually like /usr/local/.

When you compile your code, you can just indicate the compiler where to find the libraries by -I. For example, g++ -I /usr/local/boost_1_59_0 xxx.hpp.

Ethiopia answered 23/11, 2015 at 2:56 Comment(3)
This would only work for header libraries of boost. The rest of them would need to be built or installed using a package manager as described in the above answers. The boost libraries that require separate building and installation are the following: atomic, chrono, container, context, coroutine, coroutine2, date_time, exception, filesystem, graph, graph_parallel, iostreams, locale, log, math, mpi, program_options, python, random, regex, serialization, signals, system, test, thread, timer, type_erasure, wave.Chin
Even repairing this solution by following Elias Kouskoumvekakis's further instructions would be a bad idea (unless you have a good reason), since package managers add the ability to very easily update Boost to newer versions (in Ubuntu, just a sudo apt update; sudo apt upgrade to upgrade all your packages to the latest versions in the repositories) if you find the appropriate package repository for Boost and to very easily delete Boost from the system if you want to. The manual approach makes those tasks harder, so you need a good reason to skip out on the benefits of a package manager.Viator
Also, installing without a package manager is better covered in an earlier answer, which includes necessary building instructions.Viator
G
3

Install libboost-all-dev by entering the following commands in the terminal

Step 1

Update package repositories and get latest package information.

sudo apt update -y

Step 2

Install the packages and dependencies with -y flag .

sudo apt install -y libboost-all-dev

Now that you have your libboost-all-dev installed source: https://linuxtutorial.me/ubuntu/focal/libboost-all-dev/

Gerdi answered 14/9, 2020 at 14:59 Comment(0)
D
0

I was looking for any small guides - how to install boost latest release in Rocky Linux, however the same guide applies for any Generic Linux (CentOS, Ubuntu, Debian, Rocky, Fedora)

  1. Download and extract the latest Boost release, inside the folder
sudo ./bootstrap.sh --prefix=/usr
sudo ./b2 install --with=all

Check Boost version with

#include<iostream>
#include <boost/version.hpp>

int main(){

 std::cout << "Using Boost "     
          << BOOST_VERSION / 100000     << "."  // major version
          << BOOST_VERSION / 100 % 1000 << "."  // minor version
          << BOOST_VERSION % 100                // patch level
          << std::endl;

          return 0;

}
Dariodariole answered 3/3, 2023 at 6:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.