In this guide, we will install Hyperledger Fabric v1.4 on Linux machine and on Windows machine.
When I started learning Hyperledger Fabric, installing it is really a pain in a neck and it turned miserable as I was using Windows.
The purpose of this article to put all the instructions at one place to set up the Hyperledger Fabric network irrespective of the fact if youâre using Windows or Linux.
My apologies for macOS readers, instructions for macOS is not included as I donât have one.
Contents:
- Prerequisites
- Linux Installation
- Windows Installation
Prerequisites
- cURLâââlatest version
- Dockerâââversion 17.06.2-ce or greater
- Docker Composeâââversion 1.14.0 or greater
- Golangâââversion 1.11.x
- Nodejsâââversion 8.x (other versions are not in support yet)
- NPMâââversion 5.x
- Python 2.7
These prerequisitesâ versions are according to the fabric v1.4 documentation.
Linux Installation
Linux installation is pretty straight forward compared to windows. Few commands and Fabric is ready.
I have provisioned a Linux 16.04 VM from AWS for this article. All the instructions will run in the terminal. I havenât found any system requirement information in Hyperledger documentation. Please comment if you have a reference for the system requirement.
Step 1: Create a new sudo user
It is recommended that Hyperledger Fabric shouldnât be installed as a root user. Open the terminal.
-
Add the new user âfabricâ
sudo adduser fabric
-
Add the user âfabricâ to the Sudo groups
sudo usermod -aG sudo newuser
-
Login to âfabricâ user
su fabric
-
Test the sudo access
sudo ls
If you get any error then the user is not added to the sudo group. Follow this link for more information.
Step 2:Â cURL
Check if your Linux has curl install or not. curl --version
If not follow the below instructions to install:
sudo apt-get update
sudo apt-get install curl
curl --version
Step 3: Docker and Docker Compose
-
Install the latest version of Docker from the official Docker repository.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
-
Add the Docker repository to APTÂ sources
sudo add-apt-repository âdeb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stableâ
-
Update the package database
sudo apt-get update
-
Install Docker
sudo apt-get install -y docker-ce
-
To use docker commands it requires root privileges. Instead of using sudo for all the docker commands, add the user to docker group
sudo usermod -aG docker fabric
-
Logout using exit command and log in again. Check the groups' user is part of, using id -nGÂ command.
Output fabric sudo docker
Test the Installation
-
Check the docker and docker-compose version
docker --version docker-compose --version
-
Pull the hello-world image from Docker Hub and run a container:
docker run hello-world
docker hello world
If you get this message then your is successfully installed.
For more information, please follow this link.
Step 3:Â Golang
-
Install the golang package
curl -O https://storage.googleapis.com/golang/go1.11.linux-amd64.tar.gz
-
Extract the package
tar xvf go1.11.linux-amd64.tar.gz
-
Check the go version
go version
-
Set the GOPATH
export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
For more installation information follow this link and for GOPATH follow this link.
Step 4: Nodejs and npm
-
Download the installation script using curl
curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
-
Run the script under sudo
sudo bash nodesource_setup.sh
-
Install the nodejs
sudo apt-get install nodejs
With nodejs, npm also get installed. Check their version
node -v
Output
v8.16.0
npm -v
v6.4.1
Step 5: Python 2.7
By default ubuntu 16.04 comes with Python 3.5.1 installed as python3Â binary.
-
To install python 2.7
sudo apt-get install python
-
Check the python version:
python --version Python 2.7.12
All the prerequisites are installed. Now, let's install the Hyperledger Fabric v1.4.
Step 6: Install Samples, Binaries and Docker Images
Determine the directory where you want to download the fabric samples. Open the directory in terminal and run the below command.
curl -sSL http://bit.ly/2ysbOFE | bash -s
It will download the latest production release.
If you want a specific release for ex. v1.4.1, follow the below command.
curl -sSL http://bit.ly/2ysbOFE | bash -s -- <fabric_version> <fabric-ca_version> <thirdparty_version>
curl -sSL http://bit.ly/2ysbOFE | bash -s -- 1.4.1 1.4.1 0.4.15
Itâll take some time, once it is finished you can see a new directory âfabric-samplesâ.
âfabric-samplesâ come with sample examples to start with Hyperledger Fabric. There are many good examples to play within the fabric samples.
fabric-samples
Step 7: Test the fabric network
As we have successfully completed the setting up the Fabric environment, letâs test it. To test it weâll use first-network sample in the fabric-samples.
Open the fabric-samples and go to first-network.
cd fabric-samples/first-network
first-network
To test it, run the byfn.sh . It is a test script, it first setup the network with 2 organizations org1 and org2 with 2 peers each and an orderer .
./byfn.sh up
first-network start
On successful execution, youâll see the below message.
first-network end
If you reach till this point it means you have successfully setup the fabric network.
Now, we have completed the testing of first-network, clean the network.
./byfn down
Congratulations, we have completed the Hyperledger Fabric installation in Linux machine.
<a href="https://medium.com/media/844c93b0773672b9b56411a8792a9e96/href">https://medium.com/media/844c93b0773672b9b56411a8792a9e96/href</a>
Windows Installation
For Windows installation, you should be prepared for some obstacles as installation on windows is not easy peasy.
Let's begin the windows installation.
I am using Windows 10 Pro for the Fabric v1.4 installation.
Step 1:Â cURL
Please check if cURL is already installed in your PC.
curl --help
If you donât get any error it means cURL is installed in your PC and you can go to the next step. For others please follow the below steps.
- To install cURL, download the package according to your Windows 32/64 bit from this link. Extract the package and run the curl.exe present in the bin folder.
- Add the curl in the environment variable.
- Open the cmd and check the curl --help .
If you donât get any error it means you curl is installed successfully.
Follow this link for troubleshooting.
Step 2: Docker and Docker Compose
Before installing the docker, check if virtualization is Enabled in your PC or not. To check it, openTask Manager >> Performance Tab >>Â CPU
virtualization
From the BIOS settings, virtualization can be turned to Enabled. Instructions to enter BIOS settings vary from pc manufacturer to manufacturer. Please check this link for the instructions.
Once the virtualization is Enabled we can move to download the docker.
Please be sure which Windows youâre using before installing Docker. There are 2 versions of Docker for Windows.
Docker ToolboxâââWindows 8, Windows 10Â Home
Docker DesktopâââWindows 10 Pro, Enterpriseâââ64Â bit
You first need to have an account in DockerHub to download the docker desktop. Please signup if you donât have one.
Download the docker from this link.
Note: While installing keep the settings default donât change anything.
Test the Installation
-
Open the cmd window
-
Run docker --version and docker-compose --version
docker --version Docker version 18.09.2, build 6247962
docker-compose --version docker-compose version 1.23.2, build 1110ad01
-
Pull the hello-world image from Docker Hub and run a container:
docker run hello-world
docker hello-world
If you get this message then the Docker installed successfully in your machine.
For more information on Docker check the official documentation.
Step 3:Â Golang
Download the Golang package from the official site.
Once it is installed open the command prompt and run
go version
Output
go version go1.11.5 windows/amd64
Step 4: Nodejs and npm
Download the node v8.x from this link and install it.
Check if it is installed correctly.
node -v
v8.16.0
npm -v
6.4.1
Step 5: Python 2.7
Download the python 2.7 from its official site.
While installing add python to the system Path variable. This allows you to type âpythonâ into a command prompt without needing the full path.
Change Add python.exe to Path to Will be installed on the local hard drive
python-path
Check the python installed correctly or not.
python --version
Python 2.7.16
The Hyperledger Fabric prerequisites are installed. Now, it is time to install the extra windows dependencies.
Windows Extras
Step 6: Install windows-build-tools and grpc
Install the windows-build-tools globally using npm .
Open the command prompt and run the below command.
npm install --global windows-build-tools
It will take some time around 15 minutes or more. Once it will complete you will get the below message.
windows-build-tools
Once this is done, you should also install the NPM GRPC module with the following command:
npm install --global grpc
Step 7: Install git to run the bash commands
To run the bash commands we have to install git .
Git is a set of command line utility programs that are designed to execute on a Unix style command-line environment.âââatlassian
Git Bash is an application for Microsoft Windows environments which provides an emulation layer for a Git command line experience.âââatlassian
Download the git from this link.
Hang on, for a while we are done with prerequisites and now we are on the final step to install the Hyperledger Fabric.
Step 8: Install Samples, Binaries and Docker Images
Go to the directory where you want to download the fabric samples.
Once youâre in the directory open git bash . Right-click and select Git Bash Here .
git bash
Run the below command to install Samples, Binaries and Docker Images
curl -sSL http://bit.ly/2ysbOFE | bash -s
It will download the latest production release.
If you want a specific release for ex. v1.4.1, follow the below command.
curl -sSL http://bit.ly/2ysbOFE | bash -s -- <fabric_version> <fabric-ca_version> <thirdparty_version>
curl -sSL http://bit.ly/2ysbOFE | bash -s -- 1.4.1 1.4.1 0.4.15
Itâll take some time, once it is finished you can see a new directory âfabric-samplesâ.
fabric-samples
âfabric-samplesâ come with sample examples to start with Hyperledger Fabric. There are many good examples to play within the fabric samples.
Step 7: Test the fabric network
As we have successfully completed the setting up the Fabric environment, itâs time to test it. We are going to use the first-network sample from the fabric-samples.
Open the fabric-samples and go to first-network.
cd fabric-samples/first-network
first-network
To test it, run the byfn.sh . It is a test script, it first setup the network with 2 organizations org1 and org2 with 2 peers each and an orderer .
./byfn.sh up
first-network start
On successful execution, youâll see the below message.
first-network end
If you reach till this point it means you have successfully setup the fabric network.
Now, we have completed the testing of first-network, clean the network.
./byfn down
Here, we have completed the Hyperledger Fabric installation in the Windows machine.
Yes, we successfully installed the Fabric on Windows.
<a href="https://medium.com/media/14d60a171c26635e4665be2df6bf91b3/href">https://medium.com/media/14d60a171c26635e4665be2df6bf91b3/href</a>
Hope, you like the article and save you some time.