Ubuntu is often recommended as an operating system on which to run Bitcoin Core. Although Bitcoin Core can be installed as a precompiled binary, this method won’t work in every situation. This guide shows how to compile Bitcoin Core from scratch on a clean Ubuntu 18.04 system.

Why Compile?

Compiling Bitcoin Core yourself ensure you’ll always have access to the latest release. There will be no need to depend on compiled Bitcoin Core binaries when updating, and you can stay on the bleeding edge. You can even make your own modifications if you’d like.

A secondary reason to compile from source is that it requires less trust. Although the maintainers of the Bitcoin Core binary package do a fine job, binaries are a few steps removed from source code. With each step comes the potential for unexpected issues that can’t be easily detected. Source code, in contrast, can be inspected before compilation and installation.

Yet another reason to compile from source is to enable custom behavior. For example, the Bitcoin Core GUI and wallet can be disabled if you plan to use the software without those features.

Prerequisites

Searching for the Terminal application.

The method for installing Bitcoin Core described here requires that you enter text-based commands. The preferred way to do this is through the Terminal application. To access it, click the grid button in the lower left of the desktop and type “terminal”. Click the leftmost icon labeled “Terminal” to launch the application.

Running the Terminal application. Commands are entered after the dollar sign.

The Terminal application can alternatively be accessed through the keyboard shortcut Ctrl+Alt+T.

Ubuntu uses a package manager to simplify the downloading and installation of dependencies. Over time, the configuration of these packages becomes outdated. Ensure that your version of Ubuntu has the latest package information with the following command. Enter your login password when prompted.

$ sudo apt-get update

Download the Source

We’ll use Git to download the Bitcoin Core source code. In addition to providing the current version of Bitcoin Core, Git gives ready access to all past and future versions. Enter your login password when prompted.

$ sudo apt-get install git

Next, create a source directory and clone the Bitcoin Core source repository.

$ mkdir -p src && cd src $ git clone https://github.com/bitcoin/bitcoin.git

After a short time, all files should be ready. To confirm, use the ls command.

$ ls bitcoin

Install Dependencies

Bitcoin core requires many software libraries that don’t come packaged by default with the Ubuntu distribution. The first one, build-essential , enables software to be compiled from source.

$ sudo apt-get install build-essential

Bitcoin Core relies on an old version of the Berkeley Database that is not available as a standard Ubuntu 14.04 package. Although precompiled binaries can be downloaded, in this guide we’ll compile from source.

Begin by downloading and verifying the BerkeleyDB source package.

$ wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz $ echo '12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef db-4.8.30.NC.tar.gz' | sha256sum -c

The last command should return a value of db-4.8.30.NC.tar.gz: OK .

Next, unpack the BerkeleyDB source and compile.

$ tar -xvf db-4.8.30.NC.tar.gz $ cd db-4.8.30.NC/build_unix $ mkdir -p build $ BDB_PREFIX=$( pwd )/build $ ../dist/configure -- disable -shared -- enable -cxx --with-pic --prefix= $BDB_PREFIX $ make install $ cd ../..

The remaining dependencies can be installed with a single command.

$ sudo apt-get install autoconf libtool pkg-config libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libevent-dev libqt4-dev libcanberra-gtk-module

The last package on the list will prevent the following error when running bitcoin-qt :

Failed to load module “canberra-gtk-module”

Compile Bitcoin Core

To compile Bitcoin Core, move back into the previously-cloned git repository and checkout the current release tag. At the time of the last update to this article, that version is 0.10.0. Tags can be listed with the command git tag . For now, ignore the warning about “‘detached HEAD’ state”. Next, configure build, and install the binaries.

$ cd bitcoin $ git checkout v0.16.0 $ ./autogen.sh $ ./configure CPPFLAGS= "-I ${BDB_PREFIX} /include/ -O2" LDFLAGS= "-L ${BDB_PREFIX} /lib/" --with-gui $ make

Under the bitcoin/doc directory is a file called build-unix.md containing more Linux build instructions and options.

Run Bitcoin Core

Bitcoin Core can now be run from the command line.

$ src/qt/bitcoin-qt

The Bitcoin Core welcome screen.

Running this command should bring up the Bitcoin Core welcome screen.

Alternatively, Bitcoin can be run without a GUI:

$ src/bitcoind

Install Bitcoin Core

To make Bitcoin Core available globally, use:

$ sudo make install

Bitcoin-qt can now be run from the command line in any directory and launched from the Dock.