Installing Hyperledger Fabric v2.x on Ubuntu 20.04 — Part I (Updated on 2021–05–04)

Akarsh Agarwal
5 min readOct 7, 2017

--

There is an entire library of Blockchain APIs which you can select according to the needs that suffice your application. We do have open-sourced and private libraries. E.g., IBM’s Hyperledger Fabric Project, Ethereum, OpenChain, MultiChain are a few of the open-sourced models which are popular in the industry today.

The tutorial aims to help you start and set up your development environment for a blockchain application using the IBM-Hyperledger Fabric API.

In this tutorial, we will be setting Hyperledger Fabric v2.x on Ubuntu 20.04 on a localhost server. This tutorial can be applied to Ubuntu 18.04, 16.04, and 14.04, too, but would involve specific changes to the commands.

NOTE: I’m using an AWS EC2 Instance for this tutorial. Hence, all the browser screenshots are taken from the Host machine. However, all the CLI commands and instructions have been run on EC2 while writing this tutorial.

This tutorial is broken down into two parts so that it is easier for you to understand and follow through with the steps without making the article too long. The 1st part focuses on installing the prerequisites for the API, and the 2nd part will focus on installing and running Hyperledger API itself.

Prerequisites

  • Go Language v1.16.x
  • Docker CE (Community Edition)

Go Language v1.16.x

IBM Hyperledger Fabric API uses Go for compiling and building. To install the Go Language, we need to download the package from the official Go Download Page. To follow this tutorial, select the option in the Linux section, as described in the screenshot (xx.tar.gz package).

You could also download the package using the wget command from the CLI:

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

After downloading the package, we need to extract it and move it to /usr/local/ directory so that our application can access it.

To extract and move the files, use the command:

tar -xvzf go1.16.3.linux-amd64.tar.gz
sudo mv go /usr/local

The /usr/local/ should contain a go directory after the successful execution. Here is a screenshot for you to verify and check whether you have something similar or not.

After placing the Go files, let us configure the CLI to use go commands to work from anywhere in the machine. Hence, we need to include it in our environment variables. For this, let us add the environment variables in the ~/.bashrc file. To edit that file, we use the command:

sudo nano ~/.bashrc

Include the following lines at the end of the file:

#GO VARIABLES
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
#END GO VARIABLES

The PATH variable is the environment path variable. The GOROOT variable defines the location of the go files.

To reload the environment variables, we use the following command:

source ~/.bashrc

This command gives no output but reloads all the environment variables in the background. Now, let us check the installation of go in the terminal by typing:

go

If the installation was successful, we should see the following output.

Now we have installed the go language on the host machine, and we are halfway through the set up of prerequisites for the Hyperledger fabric API.

Congrats!

Docker Engine

Consider docker as a Virtual Machine Box, which runs images with specific functionalities, just like Windows and Ubuntu; however, each Docker image is smaller in size than an Operating System. Each docker image will run a service associated with the Hyperledger network on your host. We shall cover two such services required by the network to run your application in the next part of the tutorial. We will see how to install docker in this part.

To install docker through CLI, we will need to install two packages: docker-ce and docker-compose. Docker-CE is the base package, making all the necessary files available for the docker containers to run. Furthermore, docker-compose configures the docker images.

To install docker-ce, enter the following command in the terminal.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"sudo apt-get updatesudo apt-get install -y docker-ce

The output might differ from the screenshot below. However, if it installs correctly, we should see no error.

Now, we need to enable the docker service at the startup of the system. We write the following commands:

To start the docker service:

sudo service docker start

If all goes well, there will be no output. If you get an error, please consider re-installing the docker-ce again.

To enable the docker to start at startup of the system, we use the following command:

sudo systemctl enable docker

To check if the docker service is running, type:

docker

And it would help if you got a similar output as mine.

The second part of the docker installation is the docker-compose function, used to configure the docker images you are calling.

For that, we use Python’s pip3. Let us use the following command to install docker-compose:

sudo pip3 install docker-compose

The installation should complete without any red text at the bottom. However, to work with the docker images, we need to add the user to the docker group created during the installation of docker-ce.

sudo usermod -aG docker ${USER}

This command will provide no output. After completing, this adds your current logged-in user to the docker group, which will enable you to run docker images.

NOTE: Some systems need to be restarted to be able to run docker containers after the installations.

So, at this point, we have set up our two essential packages, go and docker-ce, which are required to run the Hyperledger Fabric API. In the next part of the tutorial, we will set up the Hyperledger Fabric API.

Last Update Date: 2021–05–04

--

--

Akarsh Agarwal
Akarsh Agarwal

Written by Akarsh Agarwal

All about Distributed Systems and Stakeholder Management. #golang #distributedsystems #management

Responses (7)