How to compile Bitcoin Lightning on Ubuntu

sunny okoro
4 min readAug 24, 2022

--

Bitcoin is so much a facinating technology, I am so much in love of it.

In this blog, I will try as much as I can to walk us through the steps on how to compile Core lightning from source code.

What is the Lightning Network, it is simply a layer 2 (L2) bitcoin technology that allows for instant settlement of bitcoin transactions without a third party. This L2 technology solves the proble of bitcoin scalability as well as reduces the cost of transacting in Bitcoin drastically.

The LN seats ontop of Bitcoin network hence requires you to run a fully syned Bitcoin Node for it to run effectively.

We will go straight to the point which is compiling LN from source code. To better understand the theoritical aspect of LN, kindly make use of the link

As introcuded earlier, LN needs a fully synced Bitcoin node to function, this node can be run by you (not your node, not your rules) or can be a public node hosted by a 3rd party (not advisable) such as Blockstream, meempool.space etch.

To understand how to compile your node from source code, visit my blog post which details the steps in achieving this.

There are several implementations of Lightning such;

Core Lightning
Eclairs
LND
etc

However in this post, I will be choosing the Core Lightning approach

After your bitcoin full node has been setup, follow these steps to compile Core Lightning (CLN).

Something worth noting is that CLN only runs on Linux or MacOS, this is worth knowing.

I am running a Windows Machine with Ubuntu distibution installed using WSL (Windows Subsystem for Linux)

mkdir 'foldername' 

and clone the CLN repo from git

git clone https://github.com/ElementsProject/lightning.git

move to the doc folder and open up the installation guide

Focus on the guide that targets your Linux distribution, in my case, I am currently running Ubuntu 20.04.4

Alternatively, you can go to this directory on the github repo to access the installation guide.

After the clone, checkout to the branch of lightning you are interested in running, this is the beauty of clonning from repo directlya s opposed to installing an already compiled lightning build.

git checkout v0.11.2

For development or running tests, get additional dependencies:

sudo apt-get install -y valgrind libpq-dev shellcheck cppcheck \
libsecp256k1-dev jq

If you want to build the Rust plugins (currently, cln-grpc):

sudo apt-get install -y cargo rustfmt

The commands below ensures the complete installation of CLN on your device.

pip3 install poetry
poetry shell
poetry install
./configure --enable-developer
make
make check VALGRIND=0

You may encounter some issues at the point /configure or make command which may require you install some prerequisites, go ahead to install those dependences after which you re-run the configure command.

Once the compilation has been successful without any errors, start the lightningd server which must be done after the bitcoind server has been ran.

bitcoind && lightningd
Screenshot showing your LN daemon is running

Editing the lightning config file.

Just as we have bitcoin.conf file, core lightning has its own config file which can be accessed as shown below. if the .lightning directory doesnt exist, you can create it by using the mkdir cmd.

mkdir .lightning #to create the directoty
cd ./lightning
nano .lightning/config

See below a sample of my lightning config file. In my case, I am running a signet which must be thesame as my L1.

my lightning/config file

Once your lightning server is running as below, you can now start executing the lightning cli commands

LN CLI command

NOTE: CLN does not support REST JSONRPC commands out of the box, to achieve that, you may need some plugins to achieve this.

In the nearest future, I will be writing some posts on how to achieve this which will be very handy for devs building on CLN.

RESTful calls over LN

#BitcoinCoding
#LightningCoding

Other Resources

--

--

sunny okoro

Software Tech Lead | Solutions Architect | Father | Farmer | Jesus lover | #Fintech | @Umbrel Full Node runner | DevOps | #BitcoinCoding