211

How do you install Boost on MacOS? Right now I can't find bjam for the Mac.

3
  • 1
    You can always try like "port search <whatever>" - in your case boost - when unsure. Nov 17, 2013 at 9:17
  • I've used both macports and brew. I use them together when necessary (sudo port -t install X) but I prefer brew over macports in most cases.
    – Jacksonkr
    Apr 15, 2016 at 14:13
  • 1
    For newer M1 : arch -arm64 brew install boost works
    – Pe Dro
    Apr 26, 2022 at 5:55

11 Answers 11

335

You can get the latest version of Boost by using Homebrew.

brew install boost.

13
  • 8
    How long does it take different people? Took me 48 mins with 2 GB RAM, not sure what CPU. Jun 20, 2013 at 13:37
  • 7
    @LukeStanley AFAIK Homebrew uses pre-compiled packages ("bottles") for Boost these days, making the installation a matter of seconds.
    – Philipp
    Jul 29, 2013 at 12:35
  • 8
    Matter of seconds? I'm on Mountain Lion, 2.9GHz processor, 8GB of RAM and installation is still not complete after 15min. May 28, 2014 at 1:51
  • 10
    Took about a minute
    – rp.beltran
    Jun 13, 2016 at 18:51
  • 3
    Hi, nice answer! What if I want to install [email protected]? There is no 1.58 available with homebrew?
    – GoingMyWay
    Sep 13, 2017 at 15:18
163

Download MacPorts, and run the following command:

sudo port install boost 
7
  • 2
    if you prefer running things through root sudo -s /opt/local/bin/port install boost
    – Pungs
    Feb 12, 2013 at 16:21
  • 2
    I don't believe macports is dead inasmuch as it has fallen out of fashion. Nov 23, 2013 at 3:39
  • 3
    What about doing brew install boost boost-python?
    – ilciavo
    Jan 6, 2015 at 17:16
  • 4
    How is this accepted over the Homebrew answer? That makes no sense to me...
    – user6516765
    Oct 9, 2018 at 15:40
  • 1
    Because the asker presumably uses, or at least used to use, MacPorts.
    – saagarjha
    Feb 29, 2020 at 14:44
121

Just get the source, and compile Boost yourself; it has become very easy. Here is an example for the current version of Boost on the current macOS as of this writing:

  1. Download the the .tar.gz from https://www.boost.org/users/download/#live
  2. Unpack and go into the directory:

    tar -xzf boost_1_50_0.tar.gz
    cd boost_1_50_0

  3. Configure (and build bjam):

    ./bootstrap.sh --prefix=/some/dir/you/would/like/to/prefix
  4. Build:

    ./b2
  5. Install:

    ./b2 install

Depending on the prefix you choose in Step 3, you might need to sudo Step 5, if the script tries copy files to a protected location.

4
  • 4
    Best route if you need to link against boost_thread. The standard brew recipes don't seem to include it. May 27, 2014 at 14:52
  • If you want to install other executables that depends on boost at default runtime environment ok, use other answers, in any other case, use this answer. Best for you to know when you ara compiling with boost and how. You will have it as as it is supposed to be. And Most important, It will force you to think where boost will be on Continuous Integration (Build) server, and if has an deployment server too. Jan 5, 2015 at 5:16
  • 1
    Can you please explain step 3? @snies
    – MAS
    Oct 22, 2015 at 13:40
  • 1
    @MAS (I did not try it today. But the bootstrap.sh should come with the tar.gz file. It configures the build process and creates the bjam build tool. The "prefix" is a common option for build tools which will be prefixed to the install path. This means, that if a file would be installed in /bin it will instead be installed in /prefix/bin when the install command is issued. You can use that to avoid permission problems. For example i install optional packages i use for development in /home/snies/opt/bin instead of /bin so i don't need root permissions and don't mess up my system.
    – snies
    Oct 23, 2015 at 8:20
7

Install both of them using homebrew separately.

brew install boost
brew install bjam

6

Unless your compiler is different than the one supplied with the Mac XCode Dev tools, just follow the instructions in section 5.1 of Getting Started Guide for Unix Variants. The configuration and building of the latest source couldn't be easier, and it took all about about 1 minute to configure and 10 minutes to compile.

5

Fink appears to have a full set of Boost packages...

With fink installed and running just do

fink install boost1.35.nopython

at the terminal and accept the dependencies it insists on. Or use

fink list boost

to get a list of different packages that are availible.

5

Install Xcode from the mac app store. Then use the command:

  /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

the above will install homebrew and allow you to use brew in terminal

then just use command :

brew install boost

which would then install the boost libraries to <your macusername>/usr/local/Cellar/boost

4

In order to avoid troubles compiling third party libraries that need boost installed in your system, run this:

sudo port install boost +universal
4

Try +universal

One thing to note: in order for that to make a difference you need to have built python with +universal, if you haven't or you're not sure you can just rebuild python +universal. This applies to both brew as well as macports.

$ brew reinstall python
$ brew install boost

OR

$ sudo port -f uninstall python
$ sudo port install python +universal
$ sudo port install boost +universal
3
  • For brew there is no +universal stated?
    – IceFire
    Oct 31 at 18:46
  • But port seems promising... And actually they decided that it's not worth the effort or they cannot maintain it: github.com/Homebrew/brew/issues/10307 what a blow to brew
    – IceFire
    Oct 31 at 18:56
  • Ah but actually ports also does not support boost-build universal :(
    – IceFire
    Oct 31 at 19:41
3

you can download bjam for OSX (or any other OS) here

1
  • No hint what is bjam and why you think your answer fixes boost related issue. Sep 15, 2019 at 4:18
2

If you are too lazy like me: conda install -c conda-forge boost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.