🚀 From Zero to Blockchain: Installing Hyperledger Fabric on Ubuntu with Docker and VirtualBox

🚀 From Zero to Blockchain: Installing Hyperledger Fabric on Ubuntu with Docker and VirtualBox

Ready to dive into the world of enterprise blockchain? This guide will walk you through setting up a complete Hyperledger Fabric development environment from scratch. We'll use VirtualBox to create a virtual machine, install Ubuntu Server, and then use Docker to get Hyperledger Fabric up and running. Let's get started!


Step 1: Gather Your Tools 🛠️

Before we begin, you need to download two key pieces of software:

  1. Oracle VirtualBox: This is the virtualization software that will host our Ubuntu operating system.

  2. Ubuntu Server 24.04 LTS: We're using the Long-Term Support version for stability. The server version is lightweight and perfect for this setup.


Step 2: Create and Configure Your Virtual Machine (VM)

Once VirtualBox is installed, it's time to create the home for our Fabric network.

  1. Create a New VM: Open VirtualBox and click "New".

  2. Name and OS: Give your VM a name (e.g., "Fabric-Dev-Node") and select "Linux" as the Type and "Ubuntu (64-bit)" as the Version.

  3. Allocate Resources: This is important! To run Fabric smoothly, you need to give your VM enough power.

    • Minimum: 4 GB RAM / 2 CPUs / storage 25 GB

    • Recommended: 5 GB+ RAM / 4 CPUs / Storage 40GB

  4. Create a Virtual Hard Disk: A dynamically allocated disk of about 25-30 GB should be plenty to start.

  5. Mount the Ubuntu ISO: In the VM settings under "Storage," select the empty optical drive and choose the Ubuntu Server .iso file you downloaded. This is like inserting the installation CD.


Step 3: Install Ubuntu Server 🐧

Now, start your new VM! The Ubuntu Server installer will launch. Follow the on-screen instructions. The process is straightforward:

  • Choose your language and keyboard layout.

  • Stick with the default network settings.

  • Use the entire disk for the installation.

  • Set up your username and password.

  • Important: When prompted, make sure to install the OpenSSH server so you can easily connect to your VM.

  • Let the installation complete and then reboot. Remember to "remove" the virtual installation disk when prompted

Step 4: Standalone installation 

Now, start with the following script below save it as install.sh and do chmod +x change to root and execute 

#!/bin/bash

# Script to automate the installation of Hyperledger Fabric and Grafana on Ubuntu

# ----------------------------------------------------------------
# Hardware Prerequisites
# ----------------------------------------------------------------
# CPU: 2+ cores
# RAM: 4GB+
# Storage: 20GB+ of free disk space
# ----------------------------------------------------------------

echo "----------------------------------------------------------------"
echo "Hardware Prerequisites"
echo "----------------------------------------------------------------"
echo "Before you begin, please ensure your system meets the following hardware requirements:"
echo "- CPU: 2+ cores"
echo "- RAM: 4GB+"
echo "- Storage: 20GB+ of free disk space"
echo "----------------------------------------------------------------"
echo ""
read -p "Do you want to continue with the installation? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
    exit 1
fi

# ----------------------------------------------------------------
# Step 1: Update and upgrade system packages
# ----------------------------------------------------------------
echo "--> Step 1: Updating and upgrading system packages..."
sudo apt-get update && apt-get upgrade -y
echo "--> Step 1: Complete"
echo ""

# ----------------------------------------------------------------
# Step 2: Install prerequisites for Hyperledger Fabric
# ----------------------------------------------------------------
echo "--> Step 2: Installing prerequisites for Hyperledger Fabric (curl, git, docker, docker-compose, go)..."
sudo apt-get install -y curl git docker.io docker-compose

# Add user to the docker group
if ! groups $(whoami) | grep &> /dev/null docker; then
    sudo usermod -aG docker $(whoami)
    echo "----------------------------------------------------------------"
    echo "IMPORTANT: You have been added to the 'docker' group."
    echo "Please log out and log back in for the changes to take effect."
    echo "Then, re-run this script to continue the installation."
    echo "----------------------------------------------------------------"
    exit 1
fi

# Install Go
GO_VERSION="1.20.14"
wget https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go$GO_VERSION.linux-amd64.tar.gz
rm go$GO_VERSION.linux-amd64.tar.gz
echo "--> Step 2: Complete"
echo ""

# ----------------------------------------------------------------
# Step 3: Set up Go environment variables
# ----------------------------------------------------------------
echo "--> Step 3: Setting up Go environment variables..."
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc
echo "--> Step 3: Complete"
echo ""

# ----------------------------------------------------------------
# Step 4: Download and install Hyperledger Fabric samples and binaries
# ----------------------------------------------------------------
echo "--> Step 4: Downloading and installing Hyperledger Fabric samples and binaries..."
mkdir -p $HOME/go/src/github.com/hyperledger
cd $HOME/go/src/github.com/hyperledger
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/bootstrap.sh | bash -s
echo "--> Step 4: Complete"
echo ""

# ----------------------------------------------------------------
# Step 5: Add Fabric binaries to the system's PATH
# ----------------------------------------------------------------
echo "--> Step 5: Adding Fabric binaries to the system's PATH..."
echo 'export PATH=$PATH:$HOME/go/src/github.com/hyperledger/fabric/build/bin' >> ~/.bashrc
source ~/.bashrc
echo "--> Step 5: Complete"
echo ""

# ----------------------------------------------------------------
# Step 6: Validation
# ----------------------------------------------------------------
echo "--> Step 6: Validation..."

# Validate Hyperledger Fabric installation
echo "--> Validating Hyperledger Fabric installation..."
cd $HOME/go/src/github.com/hyperledger/fabric-samples/test-network
./network.sh up
./network.sh down
echo "--> Hyperledger Fabric validation complete."

echo ""
echo "----------------------------------------------------------------"
echo "Installation and validation complete!"
echo "----------------------------------------------------------------"
echo ""
echo "Instructions:"
echo "1. Log out and log back in for all changes to take effect."
echo "2. To access Grafana, open your web browser and navigate to http://<your-server-ip>:3000"
echo "   Default login: admin / admin"
echo "3. You can start the Hyperledger Fabric test network again by running:"
echo "   cd $HOME/go/src/github.com/hyperledger/fabric-samples/test-network"
echo "   ./network.sh up"
echo "----------------------------------------------------------------"


issues identified while using samples: 

/root/go/src/github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go/go.mod:3: invalid go version '1.23.0

in this file

change 1.23.0 to 
1.23

Comments