Setup Hyperledger Fabric 2.5.x LTS on Ubuntu 22.04 and Run Chaincode (2024)

Hyperledger Fabric may seem like a complex technology, but with the right tools and guidance, it can be an enjoyable experience to set up. Let’s dive into the fun part of setting up Hyperledger Fabric 2.5 LTS on Ubuntu 22.04!

Setup Hyperledger Fabric 2.5.x LTS on Ubuntu 22.04 and Run Chaincode (2)

Before proceeding with the Hyperledger Fabric installation, ensure that the following prerequisites are installed on your Ubuntu machine:

Git — version 2.20 or greater ($ git --version)
cURL — version 7.80.0 or greater ($ curl --version)
Docker — version 17.06.2-ce or greater ($ docker --version)
Docker Compose — version 1.27.4 or greater ($ docker-compose --version)
Go programming language — version 1.20.0 ($ go version)

Note: Do not copy and execute comments. Comments are for information purpose only.

Install Git, cURL, Docker and Docker-compose.

sudo apt update

# Git(latest)
sudo apt-get install git
# Verify installation version
git --version

# cURL(latest)
sudo apt-get install curl
# Verify installation version
curl --version

# Docker(latest)
curl -fsSL https://get.docker.com -o get-docker.sh
# ⏳
sudo sh get-docker.sh
# Add USER to docker group
sudo usermod -aG docker $USER
sudo systemctl enable docker #Optional: If you want the Docker daemon to start when the system starts, use the following.
sudo systemctl start docker
# Verify installation version
docker --version

# Docker-compose (v1.29.2)
# ⏳
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Verify installation version
docker-compose --version

Install the latest version of Go if it is not already installed (only required if you will be writing Go chaincode or SDK applications).

# Install Go (1.20.0)
wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz
sudo tar -xvf go1.20.2.linux-amd64.tar.gz

# move extracted go directory into /usr/local
sudo mv go /usr/local

# Create and redirect to the new working directory
mkdir -p $HOME/go/src/github.com/<your_github_userid>

# Setup GOROOT, GOPATH, PATH
## Open bashrc file. Mostly it's hidden.
vi ~/.bashrc
## Add below 3lines at the end of the file.
## ⚠️ Careful while setting PATH, append, but do not completely erase existing path and set Go paths else the system would not restart after next poweroff/reboot
export GOROOT=/usr/local/go
export GOPATH=$HOME/go/src/github.com/<your_github_userid>
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
## Press esc,:,wq to save and exit file.
source ~/. bashrc
# Verify set go paths
echo $GOROOT $GOPATH $PATH
# Verify installation version
go version

Let’s redirect to Go project working directory and pull the fabric installation script into the directory,

# change to Go working directory
cd $HOME/go/src/github.com/<your_github_userid>
# or
cd $GOPATH

# Pull fabric installation script file and change the access mode
curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh && chmod +x install-fabric.sh

Now, download (d)ocker images, fabric (s)amples, and (b)inaries using below command,

# ⏳
./install-fabric.sh docker samples binary
# or
./install-fabric.sh d s b

# Optional: Installing specific fabric version.
# ⚠️ No need to execute if you have execute any of the above immediate command
./install-fabric.sh --fabric-version 2.5.0 binary

Setup Hyperledger Fabric 2.5.x LTS on Ubuntu 22.04 and Run Chaincode (3)

Cheers! 🏁 We have successfully completed installing Fabric samples, Docker images, and binaries to your system.

A “fabric-samples” directory must be created after the complete execution of above steps.

# Redirect to test-network from current GOPATH
cd fabric-samples/test-network

# Spin up a sample network with channel "mychannel" ca and couchdb
./network.sh up createChannel -ca -c mychannel -s couchdb

# Deploy asset-transfer-basic go chaincode
# Below command requires "jq" package to be installed
# sudo apt-get install jq
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go/ -ccl go

Setup Hyperledger Fabric 2.5.x LTS on Ubuntu 22.04 and Run Chaincode (4)

Run the script with the -h option to see all the available options with the fabric installation script,

./install-fabric.sh -h
# Usage: ./install-fabric.sh [-f|--fabric-version <arg>] [-c|--ca-version <arg>] <comp-1> [<comp-2>] ... [<comp-n>] ...
# <comp>: Component to install one or more of d[ocker]|b[inary]|s[amples]. If none specified, all will be installed
# -f, --fabric-version: FabricVersion (default: '2.5.1')
# -c, --ca-version: Fabric CA Version (default: '1.5.6')

Below are the list of downloadable components,

  • docker to download the fabric container images.
  • binary to download the fabric binaries.
  • samples to clone the fabric-samples github repo to the current directory.
  • podman to use podman to download the fabric container images.

Execute below command from “test-network” directory,

./network.sh down
  1. The new PurgePrivateData() feature allows deleting private data history from a peer while keeping an immutable hash on the blockchain. Useful for privacy or regulatory compliance, it removes private data from state and block events. Requires V2_5 application capability and is available as a new chaincode API.
  2. The latest release includes multi-architecture binaries and docker images for maximum portability. The binaries are statically linked, and the docker images now use Ubuntu instead of Alpine, providing consistency with typical production runtime environments that use glibc and require dynamic linking of HSM modules. These updates enhance the user experience by making it easier to deploy and run the software in various environments.

If you found this article helpful, don’t forget to 👏🏼 And if you have any questions🤔 or faced any difficulties💔 following the process, feel free to drop them in 🗨️
Make sure to follow us for more informative articles on the latest blockchain technologies and stay updated on the latest developments in the industry.

Setup Hyperledger Fabric 2.5.x LTS on Ubuntu 22.04 and Run Chaincode (2024)

References

Top Articles
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 5591

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.