How to Compile Bitcoin Core from Source on Linux

ยท

Ever heard about a delicious pancake or a moving song and wanted to experience it yourself? Similarly, after discussing numerous blockchain concepts and technical terms, you might be curious about how Bitcoin software is actually built. Whether you're a developer or not, compiling Bitcoin from source offers a hands-on way to understand its ingenious design. This guide walks you through the entire process step by step.

Bitcoin's source code is open-source and hosted on GitHub, a platform for version control and collaboration. The repository, maintained by the Bitcoin Foundation, uses the MIT license, allowing anyone to freely copy, modify, and study the code. The primary language is C++, so familiarity with it is beneficial for deep exploration. The code also relies on several open-source libraries, making Linux the most straightforward environment for compilation.

Preparing the Operating System

A clean and updated system ensures a smooth compilation process. We recommend using Ubuntu 16.04 LTS Desktop, either installed natively or via a virtual machine. Begin by updating your system's package sources:

sudo apt-get update

This command refreshes the list of available software packages, ensuring you install the latest dependencies.

Obtaining the Source Code

There are two primary methods to get the Bitcoin source code: using Git or downloading a ZIP archive.

Using Git

Install Git, create a directory, and clone the repository:

sudo apt-get install git
mkdir ~/bitcoinsource
git clone https://github.com/bitcoin/bitcoin.git ~/bitcoinsource

If the download is interrupted, delete the directory and restart the process, as Git does not support resuming partial clones.

Downloading a ZIP Archive

Alternatively, download bitcoin-master.zip directly from GitHub and extract it:

unzip bitcoin-master.zip

Navigate into the extracted directory to proceed.

Installing Dependency Libraries

Bitcoin Core relies on numerous open-source libraries. Install the necessary tools and dependencies with these commands:

sudo apt-get install make gcc g++ build-essential libtool autotools-dev autoconf pkg-config libssl-dev libevent-dev libboost-all-dev libminiupnpc-dev libqt4-dev libprotobuf-dev protobuf-compiler libqrencode-dev

Key libraries include:

These libraries are also open-source, allowing full transparency and deeper study.

Berkeley DB Installation

Bitcoin uses Berkeley DB for wallet storage. Install it with:

sudo apt-get install libdb-dev libdb++-dev

Compilation Preparation

Prepare the build system using Autotools:

./autogen.sh
./configure

If you encounter a Berkeley DB version warning, use:

./configure --with-incompatible-bdb

This flag allows compatibility with newer Berkeley DB versions.

Compilation and Installation

Compile the code and install the binaries:

make
sudo make install

This process generates executables in src/qt/ and installs them system-wide in /usr/local/bin.

Testing the Build

Launch the Bitcoin Qt interface to verify success:

bitcoin-qt

The familiar Bitcoin Core GUI should appear. Alternatively, run bitcoind for the daemon version.

For compilation on macOS or Windows, consult build-osx.md and build-windows.md in the doc directory of the source code.

Managing Source Code with an IDE

Reviewing large codebases in text editors is challenging. An Integrated Development Environment (IDE) like QtCreator simplifies navigation and management.

Installing QtCreator

Download the open-source version from the official Qt website. For Linux, run:

chmod +x qt-opensource-linux-x64-5.6.2.run
./qt-opensource-linux-x64-5.6.2.run

The first command grants execution permissions, and the second starts the installation.

Importing the Bitcoin Project

  1. Open QtCreator and select File โ†’ New File or Project.
  2. Choose Import Project โ†’ Import Existing Project.
  3. Select the Bitcoin source directory and assign a project name.
  4. Skip version control setup if unnecessary.
  5. Once imported, the file structure appears in the IDE's sidebar.

Running from QtCreator

Select the bitcoin-qt executable from src/qt/ as the run target. Clicking Run launches the GUI, confirming the setup.

๐Ÿ‘‰ Explore advanced development tools

Notes:

Frequently Asked Questions

Why compile from source instead of using pre-built binaries?
Compiling from source allows you to verify the code integrity, customize build options, and gain deeper insight into Bitcoin's functionality. It is ideal for developers and enthusiasts seeking transparency.

What are the hardware requirements for compiling Bitcoin Core?
A multi-core processor, 4GB+ RAM, and at least 20GB of free disk space are recommended. Compilation is resource-intensive and may take time on older hardware.

Can I compile Bitcoin on other Linux distributions?
Yes, but dependency names and installation commands may differ. For example, on Fedora, use dnf instead of apt-get. Always check the official documentation for distribution-specific instructions.

How do I update the source code to the latest version?
If using Git, run git pull in the source directory. For ZIP downloads, manually download and replace the files. Recompile using make and sudo make install.

What should I do if compilation fails?
Check for missing dependencies, version conflicts, or network issues during dependency downloads. Review error logs and consult Bitcoin forums or GitHub issues for solutions.

Is it safe to modify the source code?
Yes, under the MIT license. However, avoid unintended changes to consensus-critical code. Test modifications on testnets before mainnet use.