A Guide to Setting-up your Cardano Development Environment

Building on the Cardano Blockchain

Introduction

The buzz around the cardano ecosystem has been gaining a lot of traction as far back as 2018 and a huge part of 2021 when smart contracts went live on the platform. In this short article I would be walking you step-by-step through the process of setting up your machine to kick-start development on Cardano.

Computer Specs

Before getting started the specification of your machine is very important. On the image below is a screenshot of what that should be like.

Note: If you are building on Windows, we recommend using WSL2 under Windows 10 as this provides a development and execution environment that is very similar to Ubuntu.

STEP 1: Installing OS Dependencies

1. For Linux

To download the source code and build it, you need the following packages and tools on your Linux system:

  • the version control system git,

  • the gcc C-compiler,

  • C++ support for gcc,

  • developer libraries for the arbitrary precision library gmp,

  • developer libraries for the compression library zlib,

  • developer libraries for systemd,

  • developer libraries for ncurses,

  • ncurses compatibility libraries,

  • the Haskell build tool cabal,

  • the GHC Haskell compiler (version 8.10.7 or above).

In Redhat, Fedora, and Centos:

sudo yum update -y
sudo yum install git gcc gcc-c++ tmux gmp-devel make tar xz wget zlib-devel libtool autoconf -y
sudo install systemd-devel ncurses-devel ncurses-compat-libs which jq openssl-devel lmdb-devel -y

For Debian/Ubuntu, use the following instead:

sudo apt-get update -y
sudo apt-get install automake build-essential pkg-config libffi-dev libgmp-dev libssl-dev libtinfo-dev libsystemd-dev zlib1g-dev make g++ tmux git jq wget libncursesw5 libtool autoconf liblmdb-dev -y

2. For Mac OS

To download the source code and build it, you need the following packages and tools on your MacOS system:

  • Xcode — The Apple Development IDE and SDK/Tools

  • Xcode Command Line Tools, you can install it by typing xcode-select --install in the terminal.

  • Homebrew — The Missing Package Manager for MacOS (or Linux)

Installing Homebrew packages

For the cardano-node and cardano-cli components to compile properly, we will need to install some libraries via brew:

brew install jq
brew install libtool
brew install autoconf
brew install automake
brew install pkg-config

You will need to install openssl3

brew install openssl@3

You will also need to install llvm if you are using an M1

brew install llvm

STEP 2: Installing the Haskell Environment

1. For Linux

The recommended way to install the Haskell tools is via GHCup. Check this page for further explanation on the installation process.

Once GHCup is installed, open a new terminal (to get an updated environment) and run:

ghcup install ghc 8.10.7
ghcup install cabal 3.6.2.0
ghcup set ghc 8.10.7
ghcup set cabal 3.6.2.0

To check the installed versions:

ghcup --version
ghc --version

You can also check the cabal directory by typing

which cabal

2. For MacOS

Same as on Linux

STEP 3: Installing Libsodium

Cardano uses a custom fork of libsodium which exposes some internal functions and adds some other new functions. This fork lives in https://github.com/input-output-hk/libsodium. Users can choose to either install that custom version of libsodium or otherwise tell cabal to use a ported version included in Cardano crypto libraries.

Create a working directory for your builds:

mkdir -p ~/cardano-src
cd ~/cardano-src

Download and Installation:

git clone https://github.com/input-output-hk/libsodium
cd libsodium
git checkout 66f017f1
./autogen.sh
./configure
make
sudo make install

Add the following to your ~/.bashrc file and source it (or re-open the terminal):

For Linux

export LD_LIBRARY_PATH=”/usr/local/lib:$LD_LIBRARY_PATH”
export PKG_CONFIG_PATH=”/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH”

For MacOS

export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/opt/homebrew/opt/openssl@3/lib/pkgconfig:$PKG_CONFIG_PATH"

#For compilers to find llvm you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib -L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include -I/opt/homebrew/opt/openssl@3/include"
PATH="/opt/homebrew/opt/libtool/libexec/gnubin:/opt/homebrew/opt/openssl@3/lib/pkgconfig:/opt/homebrew:/opt/homebrew/bin:/opt/homebrew/opt/llvm/bin:$PATH"

To access ~/.bashrc go to your root directory and type:

code .bashrc

This opens bashrc via vscode. Once you have added the line of code you have to source bahsrc to commit the newly added paths:

source ~/.bashrc

On MacOS also add the following line below to your basrc:

export PATH=”/opt/homebrew/opt/llvm/bin:$PATH”

STEP 4: Installing Secp256k1

Create a working directory for your builds

cd ~/cardano-src

Download and install libsecp256k1:

git clone https://github.com/bitcoin-core/secp256k1
cd secp256k1
git checkout ac83be33
./autogen.sh
./configure — enable-module-schnorrsig — enable-experimental
make
sudo make install

Downloading the source code for cardano-node

Download the Cardano node sources:

git clone https://github.com/input-output-hk/cardano-node.git

Change the working directory to the downloaded source code folder and checkout the relevant tag:

cd cardano-node
git checkout tags/1.35.4

Configuring the build options

We explicitly use the GHC version that we installed earlier. This avoids defaulting to a system version of GHC that might be different than the one you have installed.

echo “with-compiler: ghc-8.10.7” >> cabal.project.local

On MacOS

cabal configure — with-compiler=ghc-8.10.7

STEP 5: Building and installing the node

  1. For Linux OS

Build the node and CLI with cabal:

cabal build all

Install the newly built node and CLI commands to the ~/cardano-node-1.35.4-linux directory:

mkdir -p ~/cardano-node-1.35.4-linux
cp -p “$(./scripts/bin-path.sh cardano-node)” ~/cardano-node-1.35.4-linux
cp -p “$(./scripts/bin-path.sh cardano-cli)” ~/cardano-node-1.35.4-linux

Note: ~/cardano-node-1.35.4-linux/ should be prependeded to the $PATH.

Note, we avoid using cabal install because that method prevents the installed binaries from reporting the git revision with the --version switch.

Check the version that has been installed:

cd ~/cardano-node-1.35.4-linux
./cardano-cli - version

Repeat the above process when you need to update to a new version.

Note: As a worst-case scenario, in case the node doesn’t seem to parse the existing chain db, It might be necessary to delete the db-folder (the database-folder) before running an updated version of the node.

2. MacOS Specifications

You will need to run following commands on M1, those commands will set some cabal related options before building

echo “package trace-dispatcher” >> cabal.project.local
echo “ ghc-options: -Wwarn” >> cabal.project.local
echo “” >> cabal.project.local

Add the below lines to the cabal.project file under cardano-node/ folder

package HsOpenSSL
 extra-include-dirs: /opt/homebrew/opt/openssl@3/include
 extra-lib-dirs: /opt/homebrew/opt/openssl@3/lib

Building and installing the node:

cabal build all

Install the newly built node and CLI to the $HOME/.local/bin directory:

mkdir -p $HOME/cardano-node-1.35.3-macos
cp -p “$(./scripts/bin-path.sh cardano-node)” $HOME/cardano-node-1.35.3-macos
cp -p “$(./scripts/bin-path.sh cardano-cli)” $HOME/cardano-node-1.35.3-macos

We have to add this line below our shell profile so that the shell/terminal can recognize that cardano-node and cardano-cli are global commands. ($HOME/.zshrc or $HOME/.bashrc depending on the shell application you use)

export PATH=”$HOME/cardano-node-1.35.3-macos/:$PATH”

Once saved, reload your shell profile by typing source $HOME/.zshrc or source $HOME/.bashrc (depending on the shell application you use).

Check the version that has been installed:

cardano-cli --version
cardano-node --version

NOTE: In case you get a “Killed: 9” error when executing either cardano-node or cardano-cli, please delete any existing binary files in the $HOME/cardano-node-1.35.3-macos folder, run a cabal build all and copy the files into the relevant folder.

Congratulations, you have successfully installed Cardano components into your OS system!

Thanks for reading through, I hope you found this helpful.
Otobong Peter

Useful Reference Materials I used:
Check Out the repo on Github:
https://github.com/input-output-hk/cardano-node

Forked from Bharat: https://github.com/otobongfp/cardano-tx-sample