Hyperledger Fabric Setup With All Prerequisite

Posted By : Neeraj Kumar | 20-Sep-2017

1. Install Docker (Community Edition) on Ubuntu 16.04

update the apt index first by following:

sudo apt-get update

Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

terminal screenshot

Add the Docker repository to APT sources:
there are three architecture based packages available for Docker repository:

i). amd64 ( it’s the 64-bit architecture package):
sudo add-apt-repository "deb [arch=amd64]     https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

ii). armhf (it’s 32-bit architecture i.e. it’s ARM-86 architecture based package):
sudo add-apt-repository "deb [arch=armhf] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

iii). There is a third version of this pakage which is s390x version, which is only for z-kernel based linux:
sudo add-apt-repository "deb [arch=s390x] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

terminal screenshot

Now update the apt index with newly added repo:
sudo apt-get update

Now install from Docker’s Repo:
apt-cache policy docker-ce

terminal screentshot

Now install Docker:
sudo apt-get install -y docker-ce

terminal screenshot

Now check status of Docker Engine:
sudo systemctl status docker

terminal screenshot

To run docker without sudo
     a. sudo groupadd docker
     b. sudo gpasswd -a $USER docker
either do a 'newgrp docker' or log out and log in again


2. Install Docker Compose on Ubuntu 16.04

update the apt index first by following:

sudo apt-get update

install docker-compose on linux sysytem:

sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

terminal screenshot

then run to apply executable permissions to the downloaded binary:

sudo  chmod +x /usr/local/bin/docker-compose

check the version of docker-compose:

docker-compose version

3. Install Go programming language:

update the apt index first by following:

sudo apt-get update

we need go programming language version 1.9.x as the hyperledger fabric uses 1.9.x version of go for most of its components, to do that run following commands

cd ~

{if your ubuntu is a x86 architecture based then run}

curl -O https://storage.googleapis.com/golang/go1.9.linux-386.tar.gz

{otherwise, if your ubuntu is x64 architecture based then run}
curl -O https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz

terminal screenshot

then extract it using following command:
{if you have downloaded the 32bit/x86 version}

tar xvf go1.9.linux-386.tar.gz

{or if you have downloaded the 64bit/x64 version}

tar xvf go1.9.linux-amd64.tar.gz

now change the ownership of the extracted go folder to root:root
sudo chown -R root:root ./go

now move this go folder to the /usr/local directory
sudo mv go /usr/local

set the go path:
cd ~

sudo nano .bashrc

now add these lines at the very end of the file {before doing this, make sure you have installed the go (i.e. moved go folder) in the /usr/local/ directory}

export GOPATH=$HOME/myworkspace
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin


now load the latest updated bashrc

source .bashrc

now create the workspace directory where you will put your go projects

mkdir $HOME/myworkspace

now create a project directory
mkdir -p myworkspace/src/github.com/go_project/hello

now create a hello world program go file under this hello directory inside go_project directory
nano ~/myworkspace/src/github.com/go_project/hello/hello.go
copy the following code in it

    package main

    import "fmt"

    func main() {
        fmt.Printf("hello, world\n")

. and now save it there as hello.go  {remember you can name your program whatever you want with valid naming conventions but “.go” extension is super important}
Now run these commands to install your go program:

go install github.com/go_project/hello

now to compile it run


this should output as:

hello, world!

Congratulations! You have successfully installed go programming language on your linux system.

4. Install Node.js:

Before installing node.js itself, let’s first install nvm, it will let us install specific version of node on the machine as well as it will let us download and manage more than one versions of the node in the same machine, to download nvm:

curl -O- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

and now install node v6.11.2, be very carefull with this version of node as its required by the hyprledger fabric
nvm install 6.11.2

you can now check the version of node to be v6.11.2 specificalyy as we have installed it:
node –version

installing node eventually end up installing npm along with it, so now verify version of npm, it should be 3.10.10:
npm -v

if not the 3.10.10 version of npm in you system then run:
npm install [email protected] -g


5. Installing Python:

as ubuntu comes with Python 3.5.1 as python3 binary. Hyperledger Fabric requires Python 2.7 for “npm install” to work properly, so to install Pyhton 2.7 run following command
sudo apt-get install python -y

check the version of your python
python --version


6. Install Git:

sudo apt-get install git

7. Setting up Hyperledger Fabric:

cd ~
mkdir hyperledger-binaries
cd hyperledger-binaries/

Now lets Setup our machne for actually run a Hyperledger Fabric, run following command to download Docker Images and tag them as latest and to download Fabric binaries run it from where you wants to extract the fabric binaries:
curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0

now add the download location of these binary to your system path
cd ~

sudo nano .bashrc
source .bashrc

Now lets run this sample to test your full setup is working just fine to run the sample fabric network:

cd fabric-samples/first-network


now to generate the CA-Certificates and docker-compose end to end configuration files run:

./byfn.sh -m generate

terminal screenshot

now to actually bring the network up and install the sample chaincode on each peer at this fabric:
./byfn.sh -m up

If everything works as expected you will se a screen like this:

terminal screenshot

now run following command to see if all docker images are running in the conatiners or not:

docker ps

you should see something like this:

terminal screenshot

congratulation, you have successfully brought the fabric network up.

Now to stop and tear down the fabric:

./byfn.sh -m down

terminal screenshot

About Author

Author Image
Neeraj Kumar

Neeraj is a JAVA Developer who possesses skill set in: Data Structures, Core Java, Java Enterprise Edition (Servlets, JSP, Standard Java Beans), Spring (Spring-core, spring-MVC, spring-Data-Access, Spring-Data-JPA), Hibernate, JPA, HTML, CSS, JavaScri

Request for Proposal

Name is required

Comment is required

Sending message..