How to install Boost on Ubuntu

UbuntuBoost

Ubuntu Problem Overview


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?

Ubuntu Solutions


Solution 1 - Ubuntu

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.

Solution 2 - Ubuntu

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

Solution 3 - Ubuntu

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

Solution 4 - Ubuntu

Get the version of Boost that you require. This is for 1.55 but feel free to change or manually download yourself https://www.boost.org/users/history/">(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

Solution 5 - Ubuntu

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

Solution 6 - Ubuntu

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

sudo apt update

sudo apt install libboost-all-dev

Solution 7 - Ubuntu

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 &

Solution 8 - Ubuntu

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/

Solution 9 - Ubuntu

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionk53scView Question on Stackoverflow
Solution 1 - UbuntuAnton GuryanovView Answer on Stackoverflow
Solution 2 - Ubuntuuser3715812View Answer on Stackoverflow
Solution 3 - UbuntuEric LeschinskiView Answer on Stackoverflow
Solution 4 - UbuntuAhmed ElcheikhView Answer on Stackoverflow
Solution 5 - Ubuntux4g0tt3nSou1xView Answer on Stackoverflow
Solution 6 - UbuntuAashish BhandariView Answer on Stackoverflow
Solution 7 - UbuntuArash ForoughiView Answer on Stackoverflow
Solution 8 - UbuntunanaView Answer on Stackoverflow
Solution 9 - Ubuntujimmy.zhaoView Answer on Stackoverflow