A step-by-step guide to setting up Bitcoin Core and Lightning (lnd) on Windows Subsystem for Linux

A step-by-step guide to setting up Bitcoin Core and Lightning (lnd) on Windows Subsystem for Linux

Bitcoin remains the most disruptive payment technology in modern times as it holds the promise of eliminating middlemen and financial institutions - ensuring that users can perform transactions securely on the internet. Currently, Windows is the most popular operating system in the world. As such, to drive the adoption of bitcoin, it is important that developers who use Windows and want to build with Bitcoin or understand how Bitcoin works can do so.

In this tutorial, I would be sharing with you a step-by-step guide on how to set up Bitcoin Core and Lightning on your Windows computer using Windows Subsystem for Linux and Ubuntu.

Let's get started!

Step 1: Install and setup WSL and Ubuntu

The first step to take in this tutorial would be to setup WSL and Ubuntu on your Windows computer if you haven’t yet. To do this, you can:

  1. Enable the WSL feature. You can do this by going to the Control Panel and searching for "Turn Windows features on or off", and then checking the box for "Windows Subsystem for Linux".

  2. Restart your computer to finish enabling the WSL feature.

  3. Open the Microsoft Store and search for "Ubuntu". Download and install the app.

  4. Once the app is installed, open it and complete the setup process by creating a new user and password.

  5. You should now have a working Ubuntu command line interface running on your Windows machine.

Step 2: Download and Install Bitcoin

Here comes the technical part as we would be downloading and installing Bitcoin and its binaries from source. To this, open your Ubuntu, cd to your home directory and run:

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

(Pro tip: if you don’t have git installed, you should first install it with the command sudo apt-get install git)

Once you have successfully cloned the repo cd into bitcoin, checkout to the most recent version of bitcoin using git checkout. At the point of developing this tutorial, the most recent stable version of bitcoin was v24.0.1

Step 3: Download all required Bitcoin packages

Now, we need to download all the packages we would need to get bitcoin to run on our device. To view all the packages, you will need to read bitcoin’s build-unix.md file which can be found by running the command below in your bitcoin folder:

cd doc
less build-unix.md

The build-unix.md file contains information on which packages are required and how to run bitcoin after you have successfully installed all the packages.

In summary, to install all required packages, you need to run:

sudo apt-get install build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 libsqlite3-dev libminiupnpc-dev libnatpmp-dev systemtap-sdt-dev libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools qtwayland5  libqrencode-dev  gcc-c++ libtool make autoconf pkgconf qrencode-devel

(Pro tip: The packages are quite much so I’d suggest you install them in batches to reduce the chances of package conflict.)

Step 3: Building, Configuring and Making Bitcoin

Once you have successfully installed all the required packages, you need to run the following one-by-one to setup Bitcoin

./autogen.sh
./configure --disable-wallet
make

To test if you have successfully set up bitcoin, you can run:

make check

(Pro tip: if you encounter any errors, it is most likely because one or more dependencies have not been installed. Make sure to read between the lines of the errors to know exactly the issue and debug accordingly)

Step 4: Setup your Bitcoin Conf file(bitcoin.conf)

If you got to this stage without any errors, you can now proceed to set up your Bitcoin conf file. Think of your Bitcoin.conf file as a settings page that contains all the configuration information you would like your Bitcoin setup to have.

To setup bitcoin.conf, you need to find your .bitcoin folder which was generated when you ran “make”. To find .bitcoin, run:

find ~/ -name .bitcoin

Now, cd to the folder that your .bitcoin is in and create your bitcoin.conf file by running

touch bitcoin.conf

Open the bitcoin.conf folder by running:

 nano bitcoin.conf

and then copy the following into your bitcoin.conf file:

dbcache=1536
server=1
par=1
maxuploadtarget=137
maxconnection=16
testnet=1
fallbackfee=0.00001
test.rpcport=18332
daemon=1
rpcauth=yourrpcauth
rpcuser=yourusername
rpcpassword=yourpassword
rpcallowip=127.0.0.1
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
prune=1000
[test]
rpcbind=127.0.0.1
rpcport=18332
[main]
rpcbind=127.0.0.1
rpcport=8332
[regtest]
rpcbind=127.0.0.1
rpcport=18443

(Pro tip: to generate your rpcauth, run sudo ./share/rpcauth/rpcauth.py within your bitcoin core passing your username. Your rpcusername and rpcpassword are usually your username and password set up with Ubuntu)

Step 5: Run Bitcoind, Bitcoin-cli and mine some blocks

Hopefully, this article has been smooth sailing for you so far without any errors. Now, you can run bitcoind to start Bitcoin.

bitcoind

You can also easily mine some blocks by first creating a wallet:

bitcoin-cli createwallet “newWallet”

And then generating some blocks:

bitcoin-cli -generate 5

Now you can view your Bitcoin wallet balance with:

bitcoin-cli getbalance

(Pro tip: you can also setup aliases to make running your bitcoin smoother, you can do that by making changes to your .bash_profile or .bashrc file. A great guide to doing that can be found here)

Note that your bitcoin setup is currently running in Regtest, hence no actual bitcoin mining process is happening.

Bitcoin has 3 major testing networks: Regtest, Testnet and Signet.

Here is a brief definition of each:

Regtest: (short for "regression test") is a local testing environment that allows developers to create a private, simulated network for testing purposes. It is typically used for testing new features or changes to the Bitcoin protocol.

Testnet: is a public testing environment that is separate from the main Bitcoin network. It is used by developers to test their applications and try out new features before they are released on the main network.

Signet: a new type of testing network for Bitcoin, it is similar to testnet but it is a trust-based system, where all the blocks are created by a single entity. It allows for more controlled and predictable testing, making it more suitable for certain types of testing and development

Step 6: Setting up Lightning

Lightning is a second-layer solution built on bitcoin that enables users to create payment channels between themselves, rather than having to make all transactions directly on the blockchain. Since Lightning was built with Go, you will need to first install Go on your device before you can run Lightning.

To install go, run:

wget https://dl.google.com/go/go1.18.linux-amd64.tar.gz

Once the Go package has been installed, you can proceed to extract and export it to path with the code below:

sudo tar -C /usr/local -xzf go1.18.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

Once you've run this successfully, you would need to setup your GOPATH in your .bashrc to ensure that your shell will be able to detect the binaries you install.

export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin

Installing lnd from source

With Go setup successfully, you can install lnd, lncli and all related dependencies by running the following commands:

git clone https://github.com/lightningnetwork/lnd
cd lnd
make && make install

Tests

First, ensure that Bitcoin core is running. Then to check that lnd was installed properly run the command below:

make check

Step 7: Setup your Lightning Conf file (lnd.conf)

Again, to setup lnd.conf, you need to find your .lnd folder which was generated when you ran “make”. To find .lnd, run:

find ~/ -name .lnd

Then create a lnd.conf file within the folder and copy the following into it:

[Bitcoin]

bitcoin.active=1
bitcoin.regtest=1
bitcoin.node=bitcoind

[Bitcoind]

bitcoind.rpchost=localhost
bitcoind.rpcuser=yourrpcusername
bitcoind.rpcpass=yourrpcpassword
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333

Step 8: Run LND

For this part, you might need to have two Ubuntu terminals open. On one of the terminals, run:

lnd

With lnd and bitcoind running, you can now proceed to create a lightning wallet by running

lncli create

And that's it you have successfully set up your lnd and lncli. Please note that Lightning usually requires atleast two nodes to open a channel between each other and perform transactions, so you would need to setup a second lightning node. You can easily do this by following the tutorial written by Michael Goldstein which can be found here

Pro tip: to get lnd and lncli commands to run, you need to be running bitcoin core in the background, so always ensure that Bitcoin is running. To read more on setting up lightning, you can read the lightning documentation

Conclusion

And that’s it. In just 8 steps, we were able to successfully setup Bitcoin Core on Regtest. You can continue to play around with bitcoin in ubuntu using the commands that can be found here. You can also try to perform some lightning transactions after setting up your second lightning node.

Happy Hacking! ✌🏼