Hyperledger Fabric is an exciting technology and is progressing rapidly with the approach of move fast and break things so it can sometimes turn out to be a soul-destroying task to set up the Fabric development environment. Even the official documentation falls short of discussing everything there is in setting up the environment. So, I have written this guide to lay down all the steps you will need to go through to set up the development environment. I will try to keep this guide updated to reflect the latest changes in the Fabric protocol.]
I am not going to bore you with explaining what blockchain is and why it matters and explain the use cases of permissioned blockchain technology frameworks like Hyperledger Fabric. If you want to learn the basics of blockchain, Hyperledger Fabric, and its use cases. There is no better way than to study the official documentation here.
Installing one wrong package version might generate errors that can take days to debug. These steps have been tested to work well on Ubuntu 18.04 LTS.
Let us get started.
cURL is a tool that is used to transfer data over the internet.
sudo apt-get install curl
Docker is a tool designed to make it easier to create, deploy, and run applications in virtual containers. We will use docker to set up simulate different peers in the network. We use docker CLI container to interact with the peers and ordering service, install and upgrade chaincode, and create and join channels.
If you previously installed docker on your machine. You will need to remove all previous docker packages.
dpkg -l | grep -i docker
sudo apt-get purge -y docker-engine docker docker.io docker-ce
sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce
sudo rm -rf /var/lib/docker
sudo rm /etc/apparmor.d/docker
sudo groupdel docker
sudo rm -rf /var/run/docker.sock
You have now successfully removed Docker from the system completely.
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg agent software-properties-common
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 docker-ce docker-ce-cli containerd.io
Run the command to run hello-world docker image.
sudo docker run hello-world
You need to eliminate the requirement of using sudo while working with docker
sudo groupadd docker
sudo usermod -aG docker $USER
docker run hello-world
Docker Compose is a tool for running multi-container Docker applications. You need to define all the containers that your application depends on in a .yaml file. Then, with one single command, all the service are started and your application starts running.
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Go language is used to write chaincode business logic for the channels. You can also write chaincode in Node.js and Java. Whichever language you decide to use, you need to set up the $GOPATH.
sudo apt-get install golang-go
export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
sudo apt install nodejs
node -vnpm -v
You need to set a new prefix for npm to eliminate the need of using sudo while installing packages.
npm config set prefix '~/.npm-global'
The documentation of Hyperledger Fabric provides a script that will download and install samples and binaries to your system. These sample applications installed are useful to learn more about the capabilities and operations of Hyperledger Fabric.
curl -sSL http://bit.ly/2ysbOFE | bash -s 1.4.0
This will install 1.4 version of Hyperledger Fabric binaries.
The command above downloads and executes a bash script that will download and extract all of the platform-specific binaries you will need to set up your network.
It also retrieves some executable binaries that are needed in development and places them in the
bin sub-directory of the current working directory.
The above command will bootstrap a sample network with fabcar chaincode installed. You can head to here to learn more about the network that we have just started.
After a year of development on Hyperledger Fabric framework, I have realized the importance of getting small things right when setting up the environment. Many errors that you might face during development might well be due to the mistakes in setting up the environment.
I hope this guide will help beginners starting to learn this new technology. Please feel free to point out mistakes in this guide.
Interested in starting your own blockchain project, but don’t know how? Get in touch at https://xord.solutions/contact