In this article, I explain how to compile bitcoin core from source on linux and how to then install it on your linux node. This guide is for anybody, who wants to make a dedicated node box on an Ubuntu server or similar linux distro. It is based on john atacks excellent guide, which can be found here. I have made some modifications because I have run into some slight isses with the original guide, when i wanted to compile the software on my Lenovo m73 node box computer.

Preparations

It is tweaked for linux systems and optimized for Ubuntu 22.04 LTS, but also works on older releases. ssh into your machine, or open up a terminal window if you've got physical access and a screen. I am running Ubuntu server, so for me it has to be ssh:

ssh satoshi@192.168.1.33

I have chosen satoshi as my username during linux installation. Replace satoshi with your user name and add your ip address instead of using mine. You can find your ip address on a linux device by typing ip addr

ssh yourusername@youripaddress

You're in your home directory. Let's download bitcoin from Github:

git clone https://github.com/bitcoin/bitcoin.git

Let's also install all of the dependencies:

sudo apt-get install automake autotools-dev bsdmainutils build-essential ccache git libboost-dev libboost-filesystem-dev libboost-system-dev libboost-test-dev libevent-dev libminiupnpc-dev libnatpmp-dev libqt5gui5 libqt5core5a libqt5dbus5 libsqlite3-dev libtool libzmq3-dev pkg-config python3 qttools5-dev qttools5-dev-tools qtwayland5 systemtap-sdt-dev

Let's move into the bitcoin directory and install Berkeley DB v4.8:

cd bitcoin && ./contrib/install_db4.sh `pwd`

We see a promt in the end if everything went well:

db4 build complete.
When compiling bitcoind, run `./configure` in the following way:
export BDB_PREFIX='/home/satoshi/db4'
./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include" ...

We can now set the environment variable BDB_PREFIX using export BDB_PREFIX='<PATH-TO>/db4', where <PATH-TO> is replaced by your bitcoin folder. In my case it read:

export BDB_PREFIX='/home/satoshi/bitcoin/db4'

Your output will have your path in it. Don't copy paste my line unless your user is also satoshi and the git bitcoin clone is sitting in your home folder. For you, it will be your path:

export BDB_PREFIX='/path/to/your/bitcoin/db4'

Now let's see all available versions for compilation by running:

git tag -n | sort -V

At the moment of me typing this, the newest bitcoin version is v23.

To install version 23, run

git checkout v23.0

For other versions use their tag such as

git checkout v0.21.2

for instance.

Now, run ./autogen.sh and once that's done run

./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include"

Compilation and Installation

We are ready for compilation. Compile with

make -j "$(($(nproc)+1))"

to run compilation on multiple cores in parallel or just

make

to compile on one core only. Both options take some time and might make your fans spin up. That's fine. The multicore compilation is faster, which is why I've suggested it first.

With that done, you can now install the software with

make install

Then type which bitcoind

to see which path the installer puts bitcoind into. We've now got bitcoind installed.

Optional tests

Before installation using make install, you can run unit tests using

make -j "$(($(nproc)+1))" check or make check.

Finally, you can also run all of the functional tests using

test/functional/test_runner.py --extended

I am not recommending runnning these in parallel using

test/functional/test_runner.py -j 60 --extended

because that failed for me when it passed fine without parallelization.

Make bitcoind a service:

Finally, we want to start bitcoind every time the machine boots up.

To that end, let's make a service and put the service file in path

/etc/systemd/system/bitcoind.service

So, type

sudo nano /etc/systemd/system/bitcoind.service

These are my settings:

[Unit]

Description=Bitcoin daemon

Documentation=https://github.com/bitcoin/bitcoin/blob/master/doc/init.md

After=network-online.target

Wants=network-online.target

[Service]

ExecStart=/usr/local/bin/bitcoind -daemon \

-pid=/run/bitcoind/bitcoind.pid \

-conf=/home/satoshi/.bitcoin/bitcoin.conf \

-datadir=/home/satoshi/.bitcoin

PermissionsStartOnly=true

Type=forking

PIDFile=/run/bitcoind/bitcoind.pid

Restart=on-failure

TimeoutStartSec=infinity

TimeoutStopSec=600

User=satoshi

Group=satoshi

RuntimeDirectory=bitcoind

RuntimeDirectoryMode=0710

ConfigurationDirectory=bitcoin

ConfigurationDirectoryMode=0710

StateDirectory=bitcoind

StateDirectoryMode=0710

PrivateTmp=true

ProtectSystem=full

NoNewPrivileges=true

PrivateDevices=true

MemoryDenyWriteExecute=true

[Install]

WantedBy=multi-user.target

ExecStart=/usr/local/bin/bitcoind needs to point to the location that contains bitcoind

if which bitcoind qives you a different path from /usr/local/bin/bitcoind, use that path instead. Your datadir and your configuration might also be differnt.

With your service file saved (ctrl-o, y, ctrl-x), run

sudo systemctl enable bitcoind.service

sudo systemctl start bitcoind.service

sudo systemctl status bitcoind.service

You can type

bitcoin-cli getbestblockhash to see if everything works. It does if you get an output that looks something like this:

0000000000000000000322baf991af47977e2fbbc5118099d9659ba9c9a6855f

That's it. You've compiled bitcoin core from source on Ubuntu, installed it and made a service file for it to launch whenever your node boots. Nice. This also works on other linux distros but you might have different paths.

You have reached the end of Compile bitcoin core from source on linux Thank you for your attention.
Have you considered signing up for a bitcoin savings plan? If you set up one with Swan bitcoin you get 10 dollars for free with my referral.

Support Me

You've reached the end of Compile bitcoin core from source on linux This website was made and is maintained by Jogi. You can follow me on twitter here: @proofofjogi. You can also directly support bitcoin is the better money dot com by leaving me a tip if you would like to. Thank you for your support.

Disclaimer

This website is for entertainment purposes and education only and should not be considered investment advice, because I am no licensed investment advisor and I have not considered your personal situation as a fiduciary. What you read here are my opinions only and my opinions can be wrong. Do you research and consult a professional.
Blog Return Calculator DCA Calculator