[Guide] How to install Hyperledger Fabric on Ubuntu 16.04?

(Naveen Honest Raj) #1

I’m getting into Blockchain development, which has been my fascination for the past few months. While I am able to do the development on my Mac, just wondering how I could go live with the product that I’m creating.


My base server would be Ubuntu 16.04 headless. Hyperledger Fabric would drive my stack. How do I install and use Hyperledger on Ubuntu 16.04?

(Karthik Kamalakannan) #2

Installing Hyperledger Fabric on Ubuntu 16.04 is pretty straightforward. But it does require some attention, since you don’t want to waste time in fixing things that could have been done right the first time.

I would like to confine the scope of this response to a beginner. And I’ll jump directly to the command that you would have to execute to get this done.

The Basics

Update the system: sudo apt-get update && sudo apt-get upgrade -y

Install Docker

Add Docker Key to APT: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add Docker to repo: sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Update APT again: sudo apt-get update
Install Docker Community Edition: sudo apt-get install -y docker-ce
Install Docker Compose: sudo apt-get install docker-compose
Check if Docker is up and running: sudo systemctl status docker
Execute Docker without sudo sudo usermod -aG docker ${USER} && su - ${USER}
Give permission to your username sudo usermod -aG docker <your username>

Install Hyperledger Fabric via Docker Hub


Run: docker pull yeasy/hyperledger-peer

Run Docker as a Deamon:

docker run --name=vp0 \
                    --restart=unless-stopped \
                    -it \
                    -p 7050:7050 \
                    -p 7051:7051 \
                    -e CORE_PEER_ID=vp0 \
                    -e CORE_VM_ENDPOINT= \
                    -e CORE_PEER_ADDRESSAUTODETECT=true \
                    -e CORE_NOOPS_BLOCK_TIMEOUT=10 \
                    yeasy/hyperledger-peer:latest peer node start

Pull Hyperledger Fabric PBFT:

git clone https://github.com/yeasy/docker-compose-files
cd docker-compose-files/hyperledger
docker-compose up

Move in into the Container:

docker exec -it vp0 bash

Install the Chaincode

Once you are inside the HL PBFT Container, deploy the Chaincode:

peer chaincode deploy -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c '{"Function":"init", "Args": ["a","100", "b", "200"]}' 13:16:35.643 [crypto] main -> INFO 001 Log level recognized 'info', set to INFO 5844bc142dcc9e788785e026e22c855957b2c754c912702c58d997dedbc9a042f05d152f6db0fbd7810d95c1b880c210566c9de3093aae0ab76ad2d90e9cfaa5

Start the container

Once you set the Chaincode, start the container:

docker run --name=node_vp0 \
                    -e CORE_PEER_ID=vp0 \
                    -e CORE_PBFT_GENERAL_N=4 \
                    --net="host" \
                    --restart=unless-stopped \
                    -it --rm \
                    -p 5500:7050 \
                    -p 7051:7051 \
                    -v /var/run/docker.sock:/var/run/docker.sock
                    -e CORE_LOGGING_LEVEL=debug \
                    -e CORE_PEER_ADDRESSAUTODETECT=true \
                    -e CORE_PEER_NETWORKID=dev \
                    -e CORE_PEER_VALIDATOR_CONSENSUS_PLUGIN=pbft \
                    -e CORE_PBFT_GENERAL_MODE=classic \
                    -e CORE_PBFT_GENERAL_TIMEOUT_REQUEST=10s \
                    yeasy/hyperledger-peer:latest peer node start

This should set all your required libraries and stack to run your application. :slight_smile: Hope this helps!

(VK Blue) #3

Step 1

curl -O https://hyperledger.github.io/composer/prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu. sh
mkdir ~/fabric-tools && cd ~/fabric-tools

Step 2

curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip
unzip fabric-dev-servers.zip
cd ~/fabric-tools

Thats it

(Karthik Kamalakannan) #4

Hey @vkblue,
Thanks for sharing. Your method makes is look super easy to install Hyperledger Fabric on Ubuntu. :slight_smile:

(Ammu27) #5

this 2 steps enough for hyperledger fabrics?

(Karthik Kamalakannan) #6

Yes. This is enough for the basic setup of Hyperledger Fabric setup.

(Ammu27) #7

i have done with marbles, output also perfect . Is it possible that i can link with my front end application with marbles?

(Naveen Honest Raj) #8

I think @varun’s article would be helpful for you to create an application that communicates with your “Marbles Network”

Here’s the reference to the article. https://www.skcript.com/svr/how-to-build-nodejs-application-for-your-hyperledger-composer-networks/

(Ammu27) #9

Actually i am working in hyperledger fabrics

(Varun Raj) #10

In order to setup Hyperledger Fabric in an ubuntu 16.04 instance you need the following,

  • Docker
  • Docker Compose
  • NodeJS
  • GoLang
  • Docker Images for HLF
  • Fabric Platform Tools


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 $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce
sudo usermod -aG docker ${USER}
su - ${USER}
sudo usermod -aG docker <username> //Replace <username> with your system username

Docker Compose

sudo apt-get install build-essential
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose


curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs


curl -O https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
tar xvf go1.6.linux-amd64.tar.gz
sudo chown -R root:root ./go
sudo mv go /usr/local
sudo nano ~/.profile
// Paste this in your .profile file.
export GOROOT=$HOME/go
export GOPATH=$HOME/work
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source ~/.profile

Docker Images for Hyperledger Fabric

docker pull hyperledger/fabric-tools
docker pull hyperledger/fabric-orderer
docker pull hyperledger/fabric-peer
docker pull hyperledger/fabric-javaenv
docker pull hyperledger/fabric-ccenv
docker pull hyperledger/fabric-ca
docker pull hyperledger/fabric-couchdb

[OR] If in case it says images not found, do the following.

// Pull with version
docker pull hyperledger/fabric-tools:1.2.1
docker pull hyperledger/fabric-orderer:1.2.1
docker pull hyperledger/fabric-peer:1.2.1
docker pull hyperledger/fabric-javaenv:1.2.1
docker pull hyperledger/fabric-ccenv:1.2.1
docker pull hyperledger/fabric-ca:1.2.1
docker pull hyperledger/fabric-couchdb:0.4.14

// Tag as latest
docker tag hyperledger/fabric-ca:1.2.1 hyperledger/fabric-ca:latest
docker tag hyperledger/fabric-tools:1.2.1 hyperledger/fabric-tools:latest
docker tag hyperledger/fabric-orderer:1.2.1 hyperledger/fabric-orderer:latest
docker tag hyperledger/fabric-peer:1.2.1 hyperledger/fabric-peer:latest
docker tag hyperledger/fabric-javaenv:1.2.1 hyperledger/fabric-javaenv:latest
docker tag hyperledger/fabric-ccenv:1.2.1 hyperledger/fabric-ccenv:latest
docker tag hyperledger/fabric-couchdb:0.4.14 hyperledger/fabric-couchdb:latest

Fabric Platform Tools

curl -sSL https://goo.gl/6wtTN5 | bash -s 1.2.0