Installing Bitcoin Core 0.20.1 from source on Ubuntu Raspberry Pi

The latest release

Get the source

$ git clone
$ git checkout tags/v0.20.1

Install dependencies

The hardest part of building from source is getting all the dependencies set up properly.  I get it wrong every time...

Bitcoin Core integration/staging tree. Contribute to bitcoin/bitcoin development by creating an account on GitHub.
sudo apt-get install build-essential libtool autotools-dev automake pkg-config bsdmainutils python3
sudo apt-get install libevent-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libboost-thread-dev

Install Zero MQ for integration with lightning

sudo apt-get install libzmq3-dev

I ran into the issues for the BerkeleyDB dependencies so decided to build all dependencies locally to see if that would fix it (this takes a while... it looks like it only leverages 1 core as it compiles).  The flags are telling it not to build the dependencies for building the UI (I am just using the command line) and the UPnP support.

$ cd depends
$ make NO_QT=1 NO_QR=1 NO_UPNP=1

In the future I will just build from the depends folder to start with so there are no issues and skip the package installations of the dependencies.

Install the BerkelyDB from the top level folder

$ cd ..
$ ./contrib/ `pwd`

Kick off the build of bitcoin. The params for the configure command were provided after the BerkelyDB dependencies were installed.

$ ./
$ export BDB_PREFIX='/media/samsung/source/bitcoin/db4'
$ ./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include"
$ make
$ sudo make install

(Side note... I found the command for make to run with more threads: make -j 6 - the number should be 1.5 * cores to ensure they are used at max capacity.)

I also want to change the data directory to my 1 TB USB drive so that it does not try to store blocks on the small SD card.

$ mkdir ~/.bitcoin
$ vi ~/.bitcoin/bitcoin.conf

# Paste this into config and save the file

Finally I want to run this in a screen, rather than set up a system service.  To do this, just create a new screen:

$ screen -mSL bitcoind

Then run bitcoind

$ bitcoind

You can bail out from the screen by typing Ctrl+a, then d

You can view the existing screens with

$ screen -ls
There is a screen on:
	93220.bitcoind	(08/02/20 21:49:50)	(Detached)
1 Socket in /run/screen/S-james.

And attach back to it with

$ screen -x bitcoind

You can detach and log out and the session will stay active and sync blocks.

And after all this effort... I think I may just install it from the PPA next time.  Compiling from source on a Raspberry Pi is not a fun experience.

I started syncing at 4:00 PST.

Since I don't want to monitor it and miss when it finishes, I wrote a bash script to check the hours left in blocks every 10 seconds and then exit when it hits 0.  This will let me log back in later and see the timestamp when it finished syncing.  The script was started from a stack overflow post.


while true; do
  cnt=`bitcoin-cli getblockcount`
  hash=`bitcoin-cli getblockhash ${cnt}`
  timeline=`bitcoin-cli getblock $hash | grep '"time"'`
  ltrimtime=${timeline##*\"time\": }
  hoursleft=$(((`date +%s`-$newest)/3600))

  targetCnt=$(($hoursleft + 0))

  echo `date`

  if (( $targetCnt > 1 )); then
    echo $targetCnt
    echo 'Done'
    exit 1
  sleep 10

I started this in a screen as well so it can run without an active session.

Mon Aug 3 01:07:04 UTC 2020
Mon Aug 3 01:07:15 UTC 2020
Mon Aug 3 01:07:25 UTC 2020

It looks like it is handling about 1 days worth of blocks every 10 seconds...

Grand Finale... it took 28 Hours and 38 Minutes to sync to the tip from scratch using all default configuration.  I have to say I am pretty impressed with the Raspberry Pi 4.