Install and configure Hyperledger Fabric v1.4 in Ubuntu 18.04.3 LTS
The official documentation for Hyperledger Fabric v1.4 has prerequisites that are required for blockchain application development. This article lays out the step by step guide on how to install and configure the prerequisites on Ubuntu 18.04.3 LTS.
It is assumed that you have Ubuntu 18.04.3 LTS 64-bit version installed.
Prerequisites
- cURL: latest version
- Docker and Docker Compose: 17.06.2-ce or greater
- Go: version 1.12.x
- Node.js: version 8 (8.94 and higher) or version 10 (10.15.3 and higher)
cURL
Step 1. Update the package list
sudo apt-get update
Output
jay@hlf-dev:~$ sudo apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease
Reading package lists… Done
jay@hlf-dev:~$
Step 2. Install cURL
sudo apt install curl
Step 2. Check curl version
curl --version
Output
curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL
Docker
Step 1. Update the package list
sudo apt-get update
Step 2. Install the required packages
sudo apt-get install apt-transport-https ca-certificates gnupg-agent software-properties-common
Step 3. Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Step 4. Setup the Docker stable repository
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Step 5. Update the package list
sudo apt-get update
Step 6. Install the latest version of Docker engine
sudo apt-get install docker-ce docker-ce-cli containerd.io
Step 7. Add user to Docker group
In order to run the docker commands without sudo, you need to add the current user to the docker group with the below command.
sudo usermod -aG docker $USER
To confirm if the user is added to docker group, try the command
id -nG
Output
jay adm cdrom sudo dip plugdev lpadmin sambashare docker
Step 8. Check Docker version
jay@hlf-dev:~$ docker --version
Docker version 19.03.8, build afacb8b7f0
jay@hlf-dev:~$
Step 9. Verify the Docker Engine
The below command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
docker run hello-world
Install Docker Compose
Step 1. Download the latest version of the Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Step 2. Apply executable permissions to the binary
sudo chmod +x /usr/local/bin/docker-compose
Step 3. Check Docker Compose version
jay@hlf-dev:~$ docker-compose --version
docker-compose version 1.25.5, build 8a1c60f6
jay@hlf-dev:~$
Install Go
The recommend version of Go is version 1.12.x.
Step 1. Download the tar file
curl -O https://storage.googleapis.com/golang/go1.12.9.linux-amd64.tar.gz
Step 2. Extract the tar file
tar -xvf go1.12.9.linux-amd64.tar.gz
Step 3. Move the go directory
sudo mv go /usr/local
Step 4. Update environment variables
We need to update environment variables i.e. PATH and GOPATH. For this the user’s profile needs to be updated.
nano ~/.profile
Add the below in the .profile file.
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
Save the .profile file and load the updated environment variables.
source ~/.profile
Step 5. Check go version
jay@hlf-dev:~$ go version
go version go1.12.9 linux/amd64
jay@hlf-dev:~$
Install Node.js and NPM
If you will be developing applications for Hyperledger Fabric leveraging the Hyperledger Fabric SDK for Node.js, version 8 is supported from 8.9.4 and higher. Node.js version 10 is supported from 10.15.3 and higher.
We will be installing 10.x version. Installing Node.js will also installs NPM
Step 1. Install the Node.js v10.x repository
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
Step 2. Install nodejs
sudo apt-get install -y nodejs
Step 3. Check node version
jay@hlf-dev:~$ node -v
v10.20.1
jay@hlf-dev:~$
Step 4. Check NPM version
jay@hlf-dev:~$ npm -v
6.14.4
jay@hlf-dev:~$
Install Hyperledger Samples, Binaries and Docker Images
Under Fabric 1.4.x releases, v 1.4.7 is the latest release and we will install this version.
Step 1. Before downloading the Fabric binaries, create a directory for e.g. hyperledger in your home path.
mkdir hyperledger
cd hyperledger/
Step 2. Download Fabric v1.4.7
From the hyperledger directory (for e.g. /home/jay/hyperledger) run the below command. Please note, this will take quite sometime based on your internet speed.
curl -sSL http://bit.ly/2ysbOFE | bash -s -- 1.4.7 1.4.7 0.4.20
Step 3. Update environment variable
nano ~/.profile
Add the fabric bin path to the PATH variable. Please make sure to use the path where you have downloaded fabric binaries.
export PATH=/home/$USER/hyperledger/fabric-samples/bin:$PATH
Save the .profile file and load the updated environment variables.
source ~/.profile
Testing the Hyperledger Fabric installation
Fabric comes with few fabric samples which can be used to test the fabric installation.
Step 1. Change directory to the first-network directory
cd /home/$USER/hyperledger/fabric-samples/first-network
Step 2. Use the script to bring up the network.
./byfn.sh up
In case you are wondering, byfn stands for Build Your First Network. Refer here for further details.
Step 3. Verify the Docker containers
docker ps -a
Step 4. Bring down the network
./byfn.sh down
This concludes the steps required to setup Hyperledger Fabric v1.4 in Ubuntu 18.04.3 LTS.
Thank you for reading and I hope it was helpful! ☺️