1# macOS Build Guide
2
3**Updated for MacOS [11.2](https://www.apple.com/macos/big-sur/)**
4
5This guide describes how to build bitcoind, command-line utilities, and GUI on macOS
6
7**Note:** The following is for Intel Macs only!
8
9## Dependencies
10
11The following dependencies are **required**:
12
13Library                                                    | Purpose    | Description
14-----------------------------------------------------------|------------|----------------------
15[automake](https://formulae.brew.sh/formula/automake)      | Build      | Generate makefile
16[libtool](https://formulae.brew.sh/formula/libtool)        | Build      | Shared library support
17[pkg-config](https://formulae.brew.sh/formula/pkg-config)  | Build      | Configure compiler and linker flags
18[boost](https://formulae.brew.sh/formula/boost)            | Utility    | Library for threading, data structures, etc
19[libevent](https://formulae.brew.sh/formula/libevent)      | Networking | OS independent asynchronous networking
20
21The following dependencies are **optional**:
22
23Library                                                         | Purpose          | Description
24--------------------------------------------------------------- |------------------|----------------------
25[berkeley-db@4](https://formulae.brew.sh/formula/berkeley-db@4) | Berkeley DB      | Wallet storage (only needed when wallet enabled)
26[qt@5](https://formulae.brew.sh/formula/qt@5)                   | GUI              | GUI toolkit (only needed when GUI enabled)
27[qrencode](https://formulae.brew.sh/formula/qrencode)           | QR codes in GUI  | Generating QR codes (only needed when GUI enabled)
28[zeromq](https://formulae.brew.sh/formula/zeromq)               | ZMQ notification | Allows generating ZMQ notifications (requires ZMQ version >= 4.0.0)
29[sqlite](https://formulae.brew.sh/formula/sqlite)               | SQLite DB        | Wallet storage (only needed when wallet enabled)
30[miniupnpc](https://formulae.brew.sh/formula/miniupnpc)         | UPnP Support     | Firewall-jumping support (needed for port mapping support)
31[libnatpmp](https://formulae.brew.sh/formula/libnatpmp)         | NAT-PMP Support  | Firewall-jumping support (needed for port mapping support)
32[python3](https://formulae.brew.sh/formula/python@3.9)          | Testing          | Python Interpreter (only needed when running the test suite)
33
34The following dependencies are **optional** packages required for deploying:
35
36Library                                             | Purpose          | Description
37----------------------------------------------------|------------------|----------------------
38[librsvg](https://formulae.brew.sh/formula/librsvg) | Deploy Dependency| Library to render SVG files
39[ds_store](https://pypi.org/project/ds-store/)      | Deploy Dependency| Examine and modify .DS_Store files
40[mac_alias](https://pypi.org/project/mac-alias/)    | Deploy Dependency| Generate/Read binary alias and bookmark records
41
42See [dependencies.md](dependencies.md) for a complete overview.
43
44## Preparation
45
46The commands in this guide should be executed in a Terminal application.
47macOS comes with a built-in Terminal located in:
48
49```
50/Applications/Utilities/Terminal.app
51```
52
53### 1. Xcode Command Line Tools
54
55The Xcode Command Line Tools are a collection of build tools for macOS.
56These tools must be installed in order to build Bitcoin Core from source.
57
58To install, run the following command from your terminal:
59
60``` bash
61xcode-select --install
62```
63
64Upon running the command, you should see a popup appear.
65Click on `Install` to continue the installation process.
66
67### 2. Homebrew Package Manager
68
69Homebrew is a package manager for macOS that allows one to install packages from the command line easily.
70While several package managers are available for macOS, this guide will focus on Homebrew as it is the most popular.
71Since the examples in this guide which walk through the installation of a package will use Homebrew, it is recommended that you install it to follow along.
72Otherwise, you can adapt the commands to your package manager of choice.
73
74To install the Homebrew package manager, see: https://brew.sh
75
76Note: If you run into issues while installing Homebrew or pulling packages, refer to [Homebrew's troubleshooting page](https://docs.brew.sh/Troubleshooting).
77
78### 3. Install Required Dependencies
79
80The first step is to download the required dependencies.
81These dependencies represent the packages required to get a barebones installation up and running.
82To install, run the following from your terminal:
83
84``` bash
85brew install automake libtool boost pkg-config libevent
86```
87
88### 4. Clone Bitcoin repository
89
90`git` should already be installed by default on your system.
91Now that all the required dependencies are installed, let's clone the Bitcoin Core repository to a directory.
92All build scripts and commands will run from this directory.
93
94``` bash
95git clone https://github.com/bitcoin/bitcoin.git
96```
97
98### 5. Install Optional Dependencies
99
100#### Wallet Dependencies
101
102It is not necessary to build wallet functionality to run `bitcoind` or  `bitcoin-qt`.
103To enable legacy wallets, you must install `berkeley-db@4`.
104To enable [descriptor wallets](https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md), `sqlite` is required.
105Skip `berkeley-db@4` if you intend to *exclusively* use descriptor wallets.
106
107###### Legacy Wallet Support
108
109`berkeley-db@4` is required to enable support for legacy wallets.
110Skip if you don't intend to use legacy wallets.
111
112``` bash
113brew install berkeley-db@4
114```
115
116###### Descriptor Wallet Support
117
118Note: Apple has included a useable `sqlite` package since macOS 10.14.
119You may not need to install this package.
120
121`sqlite` is required to enable support for descriptor wallets.
122Skip if you don't intend to use descriptor wallets.
123
124``` bash
125brew install sqlite
126```
127---
128
129#### GUI Dependencies
130
131###### Qt
132
133Bitcoin Core includes a GUI built with the cross-platform Qt Framework.
134To compile the GUI, we need to install `qt@5`.
135Skip if you don't intend to use the GUI.
136
137``` bash
138brew install qt@5
139```
140
141Ensure that the `qt@5` package is installed, not the `qt` package.
142If 'qt' is installed, the build process will fail.
143if installed, remove the `qt` package with the following command:
144
145``` bash
146brew uninstall qt
147```
148
149Note: Building with Qt binaries downloaded from the Qt website is not officially supported.
150See the notes in [#7714](https://github.com/bitcoin/bitcoin/issues/7714).
151
152###### qrencode
153
154The GUI can encode addresses in a QR Code. To build in QR support for the GUI, install `qrencode`.
155Skip if not using the GUI or don't want QR code functionality.
156
157``` bash
158brew install qrencode
159```
160---
161
162#### Port Mapping Dependencies
163
164###### miniupnpc
165
166miniupnpc may be used for UPnP port mapping.
167Skip if you do not need this functionality.
168
169``` bash
170brew install miniupnpc
171```
172
173###### libnatpmp
174
175libnatpmp may be used for NAT-PMP port mapping.
176Skip if you do not need this functionality.
177
178``` bash
179brew install libnatpmp
180```
181
182Note: UPnP and NAT-PMP support will be compiled in and disabled by default.
183Check out the [further configuration](#further-configuration) section for more information.
184
185---
186
187#### ZMQ Dependencies
188
189Support for ZMQ notifications requires the following dependency.
190Skip if you do not need ZMQ functionality.
191
192``` bash
193brew install zeromq
194```
195
196ZMQ is automatically compiled in and enabled if the dependency is detected.
197Check out the [further configuration](#further-configuration) section for more information.
198
199For more information on ZMQ, see: [zmq.md](zmq.md)
200
201---
202
203#### Test Suite Dependencies
204
205There is an included test suite that is useful for testing code changes when developing.
206To run the test suite (recommended), you will need to have Python 3 installed:
207
208``` bash
209brew install python
210```
211
212---
213
214#### Deploy Dependencies
215
216You can deploy a `.dmg` containing the Bitcoin Core application using `make deploy`.
217This command depends on a couple of python packages, so it is required that you have `python` installed.
218
219Ensuring that `python` is installed, you can install the deploy dependencies by running the following commands in your terminal:
220
221``` bash
222brew install librsvg
223```
224
225``` bash
226pip3 install ds_store mac_alias
227```
228
229## Building Bitcoin Core
230
231### 1. Configuration
232
233There are many ways to configure Bitcoin Core, here are a few common examples:
234
235##### Wallet (BDB + SQlite) Support, No GUI:
236
237If `berkeley-db@4` is installed, then legacy wallet support will be built.
238If `berkeley-db@4` is not installed, then this will throw an error.
239If `sqlite` is installed, then descriptor wallet support will also be built.
240Additionally, this explicitly disables the GUI.
241
242``` bash
243./autogen.sh
244./configure --with-gui=no
245```
246
247##### Wallet (only SQlite) and GUI Support:
248
249This explicitly enables the GUI and disables legacy wallet support.
250If `qt` is not installed, this will throw an error.
251If `sqlite` is installed then descriptor wallet functionality will be built.
252If `sqlite` is not installed, then wallet functionality will be disabled.
253
254``` bash
255./autogen.sh
256./configure --without-bdb --with-gui=yes
257```
258
259##### No Wallet or GUI
260
261``` bash
262./autogen.sh
263./configure --without-wallet --with-gui=no
264```
265
266##### Further Configuration
267
268You may want to dig deeper into the configuration options to achieve your desired behavior.
269Examine the output of the following command for a full list of configuration options:
270
271``` bash
272./configure -help
273```
274
275### 2. Compile
276
277After configuration, you are ready to compile.
278Run the following in your terminal to compile Bitcoin Core:
279
280``` bash
281make        # use "-j N" here for N parallel jobs
282make check  # Run tests if Python 3 is available
283```
284
285### 3. Deploy (optional)
286
287You can also create a  `.dmg` containing the `.app` bundle by running the following command:
288
289``` bash
290make deploy
291```
292
293## Running Bitcoin Core
294
295Bitcoin Core should now be available at `./src/bitcoind`.
296If you compiled support for the GUI, it should be available at `./src/qt/bitcoin-qt`.
297
298The first time you run `bitcoind` or `bitcoin-qt`, it will start downloading the blockchain.
299This process could take many hours, or even days on slower than average systems.
300
301By default, blockchain and wallet data files will be stored in:
302
303``` bash
304/Users/${USER}/Library/Application Support/Bitcoin/
305```
306
307Before running, you may create an empty configuration file:
308
309```shell
310mkdir -p "/Users/${USER}/Library/Application Support/Bitcoin"
311
312touch "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"
313
314chmod 600 "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf"
315```
316
317You can monitor the download process by looking at the debug.log file:
318
319```shell
320tail -f $HOME/Library/Application\ Support/Bitcoin/debug.log
321```
322
323## Other commands:
324
325```shell
326./src/bitcoind -daemon      # Starts the bitcoin daemon.
327./src/bitcoin-cli --help    # Outputs a list of command-line options.
328./src/bitcoin-cli help      # Outputs a list of RPC commands when the daemon is running.
329./src/qt/bitcoin-qt -server # Starts the bitcoin-qt server mode, allows bitcoin-cli control
330```
331