How to Compile Bitcoin Core from Source
A simple guide to compiling bitcoin core from source code for Linux systems
Step 1: Installing all the dependencies
Update your system so that all your packages are up to date
$ sudo apt update
After all your packages are updated, install all dependencies
$ sudo apt-get install build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev libminiupnpc-dev libzmq3-dev libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler git libsqlite3-dev ccache
Step 2: Installing Bitcoin Core
Once all the dependencies are installed, download the Bitcoin Core repository from GitHub.
$ git clone https://github.com/bitcoin/bitcoin.git
Step 3: Installing Berkeley DB
Enter your local copy of the bitcoin repo:
$ cd bitcoin
Once you are at the root of your bitcoin repo, run:
$ ./contrib/install_db4.sh `pwd`
Once Berkeley DB is done downloading, the output should look like this:
db4 build complete.
When compiling bitcoind, run `./configure` in the following way:
export BDB_PREFIX=’<PATH-TO>/db4'./configure BDB_LIBS=”-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS=”-I${BDB_PREFIX}/include”
Take note of the output in the terminal, it will be required later.
Step 4: Compile Bitcoin Core
Your local copy of the bitcoin repo will be by default synchronized with the most recent code changes, which can be unstable. That is why, before compiling the code choose a specific version by selecting checking out a tag.
Run the following command to get a list of tags sorted by the most recent change.
$ git tag | sort -V
Select a tag like v0.21.0 by running the command
$ git checkout v0.21.0
Once you have selected the tagged branch, run the following commands
$ export BDB_PREFIX=’<PATH-TO>/db4'
Use the <PATH-TO> value from the output script from install_db4.sh$ /autogen.sh
$ ./configure BDB_LIBS=”-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS=”-I${BDB_PREFIX}/include” if using BDB 4.8, otherwise ./configure — with-incompatible-bdb
Then run
$ make
Or, if you have a CPU with multiple cores, you could make use of them and speed up the process by using your cores by
$ make -j "$(($(nproc)+1))"
Step 5: Test the build
You can check your build (which you should) by running the following commands
$ make check
Or make use of multiprocessing by
$ make -j “$(($(nproc)+1))”
Run the function test
$ test/functional/test_runner.py --extended
Omit the extended if you want to skip a few tests.
Step 6: Install Bitcoin
At this point, you can start using bitcoin by
$ src/bitcoind
Or, you can install bitcoin globally by running
$ sudo make install
This will install bitcoin globally in your system. After installing you can call bitcoind or bitcoin-cli from anywhere in your system.
Congratulations you have just compiled bitcoin from source, you have just increased the trustlessness of your setup.