# Installing Bitcoin Core on Mac OS with command line ###### tags: `bitcoin` `cli` `node` `node` `macos` _In this tutorial you can learn how to install Bitcoin Core by compiling it from source code with Command Line on a Mac OS computer._ **Table of Contents** [TOC] ## Author **BetweenPlanktonandWhales.** Twitter for corrections, comments or suggestions: [@entreplanctony1](https://twitter.com/Entreplanctony1) This tutorial was prepared for the [Socratic Bitcoin Mastering Seminar](https://libreriadesatoshi.com/) through [@libreriadesatoshi](https://twitter.com/libdesatoshi). In the following link you can find the reference documentation: [https://github.com/bitcoin/bitcoin/blob/master/doc/build-osx.md](https://github.com/bitcoin/bitcoin/blob/master/doc/build-osx.md) ## Minimum requirements Bitcoin Core full nodes have certain requirements. If you try to run a node on old hardware, it may work, but you'll probably spend more time dealing with problems. If you can meet the following requirements, you will have an easy-to-use node. - Desktop or laptop hardware running recent versions of Windows, Mac OS or Linux. - **540 gigabytes** of **free disk space**, accessible at a minimum read/write speed of 100 MB/s. :::success :bulb: If you don't have space on your computer's drive, it is possible to use an external drive to save the blockchain. ::: - At least **2 gigabytes** of memory (**RAM**) - A broadband **Internet** connection with upload speeds of **at least 50 kilobytes per second**. An unlimited connection, a connection with high upload limits, or a connection that you monitor regularly to make sure you don't exceed your upload limits. :::info :information_source: It is common for full nodes on high-speed connections to use 200 gigabytes upstream or more per MONTH. _Download usage is about 20 gigabytes per month, plus about 540 additional gigabytes the first time you start a node._ ::: - **6 hours a day** in which the entire node can be left running. (You can do other things with your computer while running a full node.) More hours would be better, and even better would be if you can run your node continuously. However, you can turn off or suspend your computer according to your needs, but ==consider that every time you turn it off the last blocks must be synchronized from the moment you turned it off.== ## Preparation :::info The commands in this guide must be executed in a command-line Terminal application. Mac OS comes with a built-in Terminal, to open it execute the key sequence **⌘+space_bar** and enter the word **terminal**. ::: Before you begin, make sure you connect your laptop or PC with a ==network cable== directly to your internet modem and disable Wi-Fi, to have the fastest and most stable internet connection possible. Make sure your computer is connected to power and in system preferences open _"Power Saver"_ to **activate the function** of _"Prevent the computer from automatically sleeping"_, the IBD It takes several days and every time your computer is suspended the download will be interrupted. ![mac-sleep](https://i.imgur.com/9tJ0I7o.jpg) Take into account that you need 540 GB of space to store the entire blockchain, so if you do not have this space available on the hard drive of your operating system, you will need to connect an external hard drive, but make sure that said drive can be mounted as ==read/write== (disks created with NTFS partitions can only be mounted as "read only" on MAC OS). :::success :bulb: **TIP:** Format your external drive as **Ex-FAT** so you can use it on Windows and Mac OS. ::: ![Ex-FAT](https://i.imgur.com/XRDRZ7P.jpg) ### Xcode Command Line Tools The Xcode Command Line Tools are a collection of tools for macOS, and must be installed in order to install Bitcoin Core from source code. Run the following command from your terminal: ```gherkin xcode-select --install ``` When you run the command a warning should appear. Click 'install' to continue the installation. ### Homebrew Package Manager Homebrew is a package manager for macOS that allows you to easily install packages from the command line. To install [_Homebrew_](https://brew.sh), run: ```gherkin /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` :::info **Note:** If you have problems installing Homebrew or downloading packages, please refer to the [troubleshooting page:link:](https://docs.brew.sh/Troubleshooting). ::: ### Required Dependencies You must download the required dependencies. These dependencies are packages that are required to perform the installation. See [dependencies.md](https://github.com/bitcoin/bitcoin/blob/master/doc/dependencies.md) for a complete list. Run the following command in your terminal: ```unix brew install automake libtool boost pkg-config libevent ``` ### Dependencies for legacy wallets In order to use legacy wallets it is necessary to install the `berkeley-db@4` package, run the command: ```unix brew install berkeley-db@4 ``` ### Clone the repository `git` should already be installed on your computer. Now, with all the dependencies installed, we must clone the _Bitcoin Core_ repository to a directory on our computer. All build scripts and commands will be executed from the directory you choose. Example, if I want to create a directory called source-code and access the contents of said directory so that the copy of _bitcoin core_ is saved there, the commands would be: ``unix mkdir /Users/${USER}/source-code cd /Users/${USER}/source-code ``` And to clone the repository: ``unix git clone https://github.com/bitcoin/bitcoin.git ``` Now you need to move to the new directory that the *git* command has created under the path you created: ``unix bitcoin compact discs ``` ### Choose the version to install To see the available versions we use the `tag` subcommand ``unix git tag ``` You can also look at the latest release version at this link: https://github.com/bitcoin/bitcoin/releases In this case we are going to select the latest version which is v24.0.1 using the `checkout` subcommand ``unix git payment v24.0.1 ``` ### GUI dependencies If you want to install the _Bitcoin Core_ graphical interface you must install the _qt@5_ package. If you don't want to use the graphical interface, you can skip this step: ``unix beer installation qt@5 ``` The graphical interface can also encode addresses in QR code. To use this function you need to install this package: ``unix install beer qrencode ``` ### Test Suite (Test Suite) There is a test suite that is very useful for testing code, if you are a developer. In order to run these tests **(recommended)** you must install python. ``unix install python ``` ### DMG file If you want _bitcoin core_ to create a file with a **.dmg** extension for installation on another computer with Mac OS, without having to compile from the source code, you must run the following command (it only works if you already have python installed): ``unix pip3 install ds_store mac_alias ``` ## Assembling Bitcoin Core ### Configuration There are many ways to configure Bitcoin Core depending on the options you want to install, here only the two most common. Both will install **bitcoind** and **bicoin-cli**, but you can control whether the other features are installed: #### Wallet and graphical interface: The following command enables GUI support and enables support for legacy wallets. If you did not install _qt_ (above) it will send you an error. If _berkeley-db@4_ is not installed, the functionality of legacy wallets will be disabled, but that of more recent wallets will be active, since _sqlite_ is installed by default on macOS. ``unix ./autogen.sh ./configure --with-gui=yes ``` #### Without wallet or graphical interface: ``unix ./autogen.sh ./configure --without-wallet --with-gui=no ``` ## Compile After configuring you are ready to compile. Run the following command (depending on your computer hardware this process may take a couple of hours, ++see the next section++): ```unix make ``` ### To speed up Compilation :bulb: Instead of just running `make` You can use the "-j N" option to compile using multiple processor cores in parallel and reduce the time it will take to compile (but it will consume more resources, keep that in mind if you are doing other activities), consult the following [link](https://www.blaess.fr/christophe/2012/01/14/parallelizing-compilations/) for more information about it, here is an example: ```unix make -j 4 ``` ### For the functional test suite To be able to run the functional tests (see Test Suite) if you installed python. ```unix make check ``` ### Create DMG file You can create an installation file with a `.dmg` extension so that you do not have to compile again if you want to install on another similar computer. This DMG will be created with all the configuration options you previously chose. ```unix make deploy ``` ## Run Bitcoin Core The Bitcoin Core executable file will have been created in the _relative path_ **`./src/bitcoind`**. This file is the **daemon** (background process) that you need to run if you are only going to use the _bitcoin core_ command line. The file **`./src/bitcoin-cli`** is the executable that you will use to interact with _Bitcoin Core_ and you should run it only after you have run **`./src/bitcoind`**, otherwise the file will send an error. And if you also compiled the graphical interface, the path will be **`./src/qt/bitcoin-qt`**. Following the example of the _"Clone the repository"_ section above, the _absolute path_ of both files would be: ```unix /Users/${USER}/source-code/bitcoin/src/bitcoind /Users/${USER}/source-code/bitcoin/src/bitcoin-cli /Users/${USER}/source-code/bitcoin/src/qt/bitcoin-qt ``` :::warning **NOTE:** you cannot run **`./src/qt/bitcoin-qt`** if **`./src/bitcoind`** is already running on the same computer, so run either commands, there should not be any active _Bitcoin Core_ instances on your computer. ::: The first time you run the bitcoind or bitcoin-qt file, the IBD process will begin, which can take days (if you want more information about this process and its implications, see this [link](https://hackmd.io/kX3hKkP1ST-wPYmqv9AdEA#La-descarga-inicial-de-bloques-IBD)). ## Location of configuration files By default, **"wallets"** and **"blockchain"** files will be saved in this directory: ```unix /Users/${USER}/Library/Application\Support/Bitcoin/ ``` You can monitor the IBD process and any activities performed by the _Bitcoin Core_ software in the `debug.log` file: ```unix tail -f $HOME/Library/Application\ Support/Bitcoin/debug.log ``` ## Before running Bitcoin Core for the first time :::success :bulb: There is a configuration file called `bitcoin.conf`, this file is not created by default and below you can see how to create it and what is the most recommended thing you can do with it before initializing your node and starting the [IBD]( https://hackmd.io/kX3hKkP1ST-wPYmqv9AdEA#The-initial-download-of-blocks-IBD) ::: ### If you want to change the default storage directory It is possible that the computer you are using does not have enough space in the default directory to store the entire blockchain (++500 GB approx++), but you can tell _Bitcoin Core_ to download it to another directory or disk on your computer . If this is your case, before running bitcoind, you can create an empty configuration file in the following location: ```unix mkdir -p "/Users/${USER}/Library/Application Support/Bitcoin" touch "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf" chmod 600 "/Users/${USER}/Library/Application Support/Bitcoin/bitcoin.conf" ``` With the text editor of your choice, you must modify the **bitcoin.conf** file that you just created so that it contains the following line: ```java datadir=/Volumes/My_disk/bitcoin ``` From the previous example we have: - **datadir** is an instruction with which we tell the software to save all the information about our node, blocks, indexes, wallets, etc. here. - **Volumes** is the path where the external disks are mounted to your operating system (external disk, pendrive, network disk). - **My_disk** is the device name of my hard drive, yours will be another one that you have defined or the name it has from the manufacturer. It is important that macOS can read and write to this disk (++see above in the preparation section of this tutorial++) - **bitcoin** is a directory that I created to separate the contents of the bitcoin node from everything else on my disk. ### Index transactions The other basic configuration of the `bitcoin.conf` file is done by adding the following line to the file: ```java txindex=1 ``` This variable allows the node to create an index of all transactions within the downloaded blocks and is used to query any transaction within the bitcoin database. ### Enable Testnet If you are going to use the Bitcoin testnet, please see: [How to run a node in testnet mode](/3J6dkl0wTCOWJXuLB_kJyA) ## Run Bitcoin Core in the background. If you run **`bitcoind`** without arguments, you cannot close the terminal you are running it in, otherwise the program will close along with the terminal window you are using. For this reason, if you want to be able to close the terminal without stopping execution, you must run the command as follows from a terminal (in this example we use the absolute path of the file but you can use the relative path): ```unix /Users/${USER}/source-code/bitcoin/src/bitcoind -daemon ``` And to stop the **`bitcoind`** program you can do it using: ```unix /Users/${USER}/source-code/bitcoin/src/bitcoin-cli stop ``` Likewise, if you decide to run the command to launch the graphical interface from a terminal, you will not be able to close the terminal or _Bitcoin Core_ will also close. To open the graphical interface from the command line so you can close the terminal: ```unix /Users/${USER}/source-code/bitcoin/src/qt/bitcoin-qt & ``` ## :zap: Donations :::success If this material was useful to you, you can thank Iván @entreplanctonyballenas, by sending him a contribution via Lightning Address: entreplanctonyballenas@getalby.com :::