If you want to run a full node on the Bitcoin network, you might want to do so on a computer that doesn't use so much power and is very inexpensive. The Raspberry Pi might seem as an obvious choice for that. Here's a tutorial on how to install the newest version of Bitcoin Core on the Raspbian OS, which is based on the Debian GNU/Linux distribution. If you have used Debian or Ubuntu Linux, you'll find many things familiar about Raspbian.
The Raspbian repositories currently contain a very old version of the original Bitcoin client, Bitcoin Core. And in fact, only the text based back-end, bitcoind, not the graphical front-end bitcoinqt. It is, however, possible to compile the newest version of Bitcoin Core yourself. This process takes a while, but most of the time the system spends on its own while you needn't intervene. To follow this tutorial, basic Linux/Unix command line experience is recommended, but probably not a requirement.
Here be dragons! Note that Bitcoin technology is generally experimental, and so is this tutorial, so don't use any significant amount of BTC with any system that you setup while following this tutorial. Also note that the relatively weak system that forms a Raspberry Pi 1 or 2, may or may not be able to handle the task of acting as a Bitcoin node satisfactorily.
- A Raspberry Pi, model B, rev 2 or model B+. Unfortunately the compiling process needs the 512 MB RAM that these models have, but it may be possible to compile on a 512 MB model, and then move the SD card to a model with 256 MB RAM afterwards.
- SD card of at least 32 GB (it must be large enough to hold the entire block chain).
- A clean install of the Raspbian OS on the SD card. Raspbian is a version of Debian Linux for the Pi. For instructions on this, please refer to the guide on raspberrypi.org.
- Network cable, and possibly a case for the Pi, and a keyboard and mouse, unless you plan to ssh into the Pi from another computer.
In order to compile and run, Bitcoin Core depends on some other tools which must be installed prior to compiling. Most are available from the Raspbian repositories and are easily installable via apt-get.
- Install Raspbian on your SD card, if you haven't done so already.
- Log into a command line on your Raspberry Pi, either via attached keyboard or make an ssh connection to it.
- Run the Pi configuration tool:
sudo raspi-configIn the menu, choose to expand the file system. Then, in "Internationalisation options", choose "Change locale", then in the list make sure that at least "en_US.UTF-8 UTF-8" is checked ("en_GB.UTF-8 UTF-8" should be checked already). Choose "OK" to build the locales. Change your timezone. Exit the Pi configuration tool and select yes when it asks to reboot. Otherwise, reboot from the command line with sudo reboot
- Change the password for your user from the default into a strong password. The is especially important if you want to run a full node and thereby run a computer connected to the Internet 24/7. But it's advised to change it anyway:
- Update your Raspbian system by issuing the two commands:
sudo apt-get update sudo apt-get upgrade
- Install some dependencies:
sudo apt-get install build-essential autoconf libssl-dev libboost-dev \ libboost-chrono-dev libboost-filesystem-dev libboost-program-options-dev \ libboost-system-dev libboost-test-dev libboost-thread-dev
- If you want the graphical frontend, also install the following dependencies. If you just want bitcoind, you can skip this step.
sudo apt-get install libqt4-dev libprotobuf-dev protobuf-compiler \ libqrencode-dev
- Create a directory which we will use for downloading and compiling various stuff, then enter it:
mkdir ~/bin cd ~/bin
Compiling and installing Berkeley DB 4.8
Compiling Bitcoin Core requires the Berkeley DB version 4.8 which is not available in the Raspbian repositories, so we must compile and install it manually. Note that if you don't need a wallet (i.e. if you want to run a headless Bitcoin node and keep your wallet elsewhere) you can completely skip this section and jump directly to downloading and compiling Bitcoin Core.
- Download the Berkeley DB, uncompress it, and cd into the uncompressed directory:
wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz tar -xzvf db-4.8.30.NC.tar.gz cd db-4.8.30.NC/build_unix/
- Then, configure the system for compiling, do the actual compile job with make (will take a good while), and then install Berkeley DB:
../dist/configure --enable-cxx make sudo make install
Downloading and Compiling Bitcoin Core
We're now ready to download and compile Bitcoin Core itself.
- Go to the branches list on the Bitcoin Core project site, locate the latest version number, and substitute "0.9.3" in the command below with that. This tutorial is known to work with version 0.9.3, but a newer version is recommended if there is one.
cd ~/bin/ git clone -b 0.9.3 https://github.com/bitcoin/bitcoin.git cd bitcoin/
- The following three commands will configure the system for compilation, then do the actual compile job. The last command make will probably take several hours to complete.
./autogen.sh ./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" \ LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" makeNote: If you skipped the Berkeley DB 4.8 dependency above because you don't need a wallet, you must add "--disable-wallet" (without the quotation marks) to the end of the line that starts with ./configure above.
Installing and Running Bitcoin Core
- To install the compiled Bitcoin Core on the system, perform the following command:
sudo make installAfter that, you will be able to run Bitcoin Core from anywhere on the system by simply typing: bitcoind (the text based backend) or bitcoin-qt (the graphical frontend).
- If you want to automatically start bitcoind on startup, e.g. if you want to set up a headless Bitcoin node, add the following line to the file /etc/rc.local:
su pi -c '/usr/local/bin/bitcoind &'Add the line anywhere before the already existing exit 0 line. You can run a text based editor by typing "sudo nano /etc/rc.local", or a graphical text editor (if you're working in a graphical environment) by typing "sudo gedit /etc/rc.local", then pasting the script above and saving (in Nano, save and exit with Ctrl-X, then Y, then Enter).
Now the bitcoind daemon will start when the system boots.
Open the port for Bitcoin traffic
If you followed this tutorial to run a full Bitcoin node, don't forget to forward traffic on port 8333 to the Raspberry Pi. How to do this varies from network to network, but typically involves entering the web interface of your network router or modem, and setting up "Port Forwarding" there. Typically this is done by simply adding the local IP address of the Raspberry Pi along with port number 8333 to a list of forwarded ports. Refer to the documentation from your router/modem's manufacturer on how to do this exactly. Some routers even do this automatically so you don't need to do anything.
In order to find your Raspberry Pi's local IP address (assuming you're not connecting to it via SSH in which case you already have the IP address), log in to it and run the command:
ip addr show eth0Look for the line that starts with the word inet. So if the line starts with "inet 192.168.1.106/24", your IP address is "192.168.1.106". You can verify that it works by checking the amount of connections after having run Bitcoin Core for a while. If it goes above 8 connections, you have successfully forwarded traffic on port 8333 to your Pi.
This concludes this tutorial on how to set up a recent version of Bitcoin Core on a Raspberry Pi. You should now be able to "sudo reboot" your Pi, whereafter it starts bitcoind and begins to download the blockchain. You can always check the status of bitcoind by logging in and typing "bitcoind getinfo".
In the future I might offer an almost ready-to-run .img file that you can just transfer to an SD card, make a few easy adjustments, and then you're ready to go, without the need for compiling any software. Although this will make it much easier to set up a Raspberry Pi Bitcoin node, it has the disadvantage that you will have to trust me not to have altered the software to do bad things. Suggestions and comments are welcome.
If you liked the tutorial, please consider donating an amount of your choice to the address or QR code to the right.