Edil Medeiros

Compile bitcoin core on macOS with macports

Last year I decided to dive deep into the bitcoin protocol development and contribute to the Bitcoin Core development. One of the most basic tasks is to be able to build the source code and run the tests. The documentation covers the build process for the major platforms, including build for macOS, which is my case.

Unfortunately, the officially supported way to install dependencies on macOS is through Homebrew. Brew is the most popular package manager for macOS. If unsure, go for it. I don’t use Brew, though, in favor on Macports. Macports offers a more unix-like experience, better control over installed packages, and it does not mess that much with the filesystem permissions.

I considered the possibility of sending a PR, but:

  • support for Macports has been dropped in 2019 in v0.18, quite a long time ago, for the lack of active maintainers for it (see PR #15175);
  • the project uses macOS images from Github CI which will include Brew but not Macports.

So, it probably does not worth the maintenance burden to get just a handful of people covered. Additionally, other than me, who uses macOS for serious stuff, anyway? Hackers should be using black plastic Linux boxes not these fancy-aluminum state-of-the-art-performance ARM boxes.

In what follows, I assume you have read the official build docs.

Required Dependencies

Install the required dependencies.

sudo port install autoconf automake libtool pkgconfig libevent python311 boost181


boost181 is the most recent version available in macports by the time of this writing. The default boost port will install version 1.76 which will compile fine, but will not enable external signer support.

This will install Python 3.11 as a dependency for boost which is fine as we are going to need it anyway. We ask for it so macports don’t clean it up in eventual maintenance routines you come to perform later. Set Macports’ Python as default with:

sudo port select --set python python311
sudo port select --set python3 python311


The key is to correctly set the environment variables (it took me a while to find them all right):

export CPPFLAGS="$CPPFLAGS -isystem /opt/local/include"
export LIBS="$LIBS -L/opt/local/lib"
export EVENT_CFLAGS="-I/opt/local/include"
export EVENT_LIBS="-L/opt/local/lib -levent"


Optional Dependencies

For legacy wallet support, we need berkeley-db.

sudo port install db48

export CPPFLAGS="$CPPFLAGS -I/opt/local/include/db48"
export LIBS="$LIBS -L/opt/local/lib/db48"
export BDB_CFLAGS="-I/opt/local/include/db48"


To build the GUI, we need qt.

sudo port install qt5


Install qrencode to include support for QR codes in the GUI.

sudo port install qrencode


miniupnpc may be used for UPnP port mapping.

sudo port install miniupnpc

export MINIUPNPC_CPPFLAGS="-isystem /opt/local/include"
export MINIUPNPC_LIBS="-L/opt/local/lib"


libnatpmp may be used for NAT-PMP port mapping. Unfortunately, there is no port available for it (maybe I should write it…).

Install zmq for ZMQ notifications.

sudo port install zmq


Build Bitcoin Core

If you haven’t yet, clone the Bitcoin Core repository.

git clone https://github.com/bitcoin/bitcoin.git


In the source code folder, don’t forget to configure the package by mentioning the boost library location.

./autogen.sh
./configure --with-boost=/opt/local/libexec/boost/1.81


If you installed all the optional dependencies I mentioned, you should get something like this at the end.

Options used to compile and link:
  external signer = yes
  multiprocess    = no
  with libs       = yes
  with wallet     = yes
    with sqlite   = yes
    with bdb      = yes
  with gui / qt   = yes
    with qr       = yes
  with zmq        = yes
  with test       = yes
  with fuzz binary = yes
  with bench      = yes
  with upnp       = yes
  with natpmp     = no
  use asm         = yes
  USDT tracing    = no
  sanitizers      =
  debug enabled   = no
  gprof enabled   = no
  werror          = no
  LTO             = no


Now make it.

Happy hacking.

Get in touch

Avenco comes with a built-in contact form.