Skip to main content

Getting cardano-node

Binaries for the latest version of the node may be downloaded from the cardano-node GitHub Releases page.

Alternatively, one can build cardano-node from source code locally.

Building from source

The preferred way of building cardano-node is via Nix, but the node is buildable also using standard Haskell tools after setting up the building environment.

Hardware requirements

To set up your platform, you will need:

NetworkCPU CoresFree RAMFree storageOS for Pasive NodeOS for Stake pool
Mainnet224GB300GB of free storage (350GB recommended for future growth)Linux / Windows / MacOSLinux
Testnet24GB20GBLinux / Windows / MacOSLinux

Building via Nix

Having Git and Nix installed on your system, run the following command to get a built cardano-node:

$ git clone https://github.com/IntersectMBO/cardano-node
$ cd cardano-node
$ git tag | sort -V
$ git switch -d tags/<TAGGED VERSION>
$ nix build .#cardano-node

Alternatively you can build a node without manually cloning the repository with:

$ nix build github:IntersectMBO/cardano-node/<TAGGED VERSION>

Consider setting up the IOG binary cache in order to avoid building the universe locally on your machine. See the IOGX template documentation for more information.

Building via cabal

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

  • the version control system git,
  • a C and C++ compiler, either gcc or clang,
  • developer libraries for:
    • the arbitrary precision library gmp,
    • the compression library zlib,
    • the service manager systemd,
    • the TUI library ncurses,
    • the key-value database lmdb,
    • the cryptographic suite openssl,
  • ncurses compatibility libraries,
  • the Haskell build tool cabal (3.10.2.0 or above),
  • the GHC Haskell compiler (version 9.6.7 or above).

System libraries

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

Installing the Haskell environment

The recommended way to install the Haskell tools is via GHCup. Its installation script will guide you through the installation, and warn you about packages that you have to make sure are installed in the system (the ones described on the step above). Check this page for further explanation on the installation process.

caution

On Windows, we discussed how to install GHCup in the step above, depending on how you want to install MSYS2.

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

ghcup install --set ghc 9.6.7
ghcup install --set cabal 3.12.1.0

Alternatively, with ghcup tui you can pick the specific versions of the tools that you want to install, in particular you should have installed and set:

  • cabal >= 3.12.1.0
  • GHC >= 9.6.7

To check that you will use the GHCup tools (and not any other installation on the system), you can execute

which cabal

and it should return a path of this shape: /home/<user>/.ghcup/bin/cabal.

Dependencies required to be at specific versions

info

Pre-built libraries can be downloaded from iohk-nix releases, following what is done in the base CI Github Action.

In particular for Windows this is probably the easiest method. Note you will need to set these variables in your .bashrc or whatever you use to source your shell:

export PKG_CONFIG_PATH=/mingw64/opt/cardano/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=/mingw64/opt/cardano/bin:$LD_LIBRARY_PATH
export PATH=/mingw64/opt/cardano/bin:$PATH

Decide which version of Cardano Node you will be installing. A list of available tags is available at: https://github.com/IntersectMBO/cardano-node/tags. Set the environment variable to the tag you selected (or use master for the latest unstable version):

CARDANO_NODE_VERSION='10.3.1'
IOHKNIX_VERSION=$(curl https://raw.githubusercontent.com/IntersectMBO/cardano-node/$CARDANO_NODE_VERSION/flake.lock | jq -r '.nodes.iohkNix.locked.rev')
echo "iohk-nix version: $IOHKNIX_VERSION"

The variable IOHKNIX_VERSION will be used going forward to retrieve the correct versions of sodium, secp256k1 and blst.

caution

Make sure that secp256k1, sodium and blst versions match flake input version in iohkNix for a particular node version used.

Installing "sodium"

Cardano uses a custom fork of sodium which exposes some internal functions and adds some other new functions. This fork lives in https://github.com/intersectmbo/libsodium. Users need to install that custom version of sodium with the following steps.

Create a working directory for your builds:

mkdir -p ~/src
cd ~/src

Find out the correct sodium version for your build:

SODIUM_VERSION=$(curl https://raw.githubusercontent.com/input-output-hk/iohk-nix/$IOHKNIX_VERSION/flake.lock | jq -r '.nodes.sodium.original.rev')
echo "Using sodium version: $SODIUM_VERSION"

Download and install sodium:

: ${SODIUM_VERSION:='dbb48cc'}
git clone https://github.com/intersectmbo/libsodium
cd libsodium
git checkout $SODIUM_VERSION
./autogen.sh
./configure
make
make check
sudo make install

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

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

For some distributions you will also need to configure the dynamic linker. If the executable is linked with the right libsodium.so file (which you can check by running ldd), the running binary might still use the wrong library. You can check this by running pldd. If the pldd shows that the running executable is using the wrong library, run ldconfig.

Installing secp256k1

Find out the correct secp256k1 version:

SECP256K1_VERSION=$(curl https://raw.githubusercontent.com/input-output-hk/iohk-nix/$IOHKNIX_VERSION/flake.lock | jq -r '.nodes.secp256k1.original.ref')
echo "Using secp256k1 version: ${SECP256K1_VERSION}"

Download and install secp256k1:

: ${SECP256K1_VERSION:='v0.3.2'}
git clone --depth 1 --branch ${SECP256K1_VERSION} https://github.com/bitcoin-core/secp256k1
cd secp256k1
./autogen.sh
./configure --enable-module-schnorrsig --enable-experimental
make
make check
sudo make install
Installing blst

Find out the correct blst version:

BLST_VERSION=$(curl https://raw.githubusercontent.com/input-output-hk/iohk-nix/$IOHKNIX_VERSION/flake.lock | jq -r '.nodes.blst.original.ref')
echo "Using blst version: ${BLST_VERSION}"

Download and install blst so that cardano-base can pick it up (assuming that pkg-config is installed):

: ${BLST_VERSION:='v0.3.11'}
git clone --depth 1 --branch ${BLST_VERSION} https://github.com/supranational/blst
cd blst
./build.sh
cat > libblst.pc << EOF
prefix=/usr/local
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include

Name: libblst
Description: Multilingual BLS12-381 signature library
URL: https://github.com/supranational/blst
Version: ${BLST_VERSION#v}
Cflags: -I\${includedir}
Libs: -L\${libdir} -lblst
EOF
sudo cp libblst.pc /usr/local/lib/pkgconfig/
sudo cp bindings/blst_aux.h bindings/blst.h bindings/blst.hpp /usr/local/include/
sudo cp libblst.a /usr/local/lib
sudo chmod u=rw,go=r /usr/local/{lib/{libblst.a,pkgconfig/libblst.pc},include/{blst.{h,hpp},blst_aux.h}}

Installing the node

Downloading the source code for cardano-node

Create a working directory for your builds:

mkdir -p ~/src
cd ~/src

Download the Cardano node sources:

git clone https://github.com/intersectmbo/cardano-node.git

Change the working directory to the downloaded source code folder:

cd cardano-node

Check out the latest version of cardano-node (choose the tag with the highest version number: TAGGED-VERSION):

git tag | sort -V
git switch -d tags/<TAGGED VERSION>
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-9.6.7" >> cabal.project.local

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

echo "package HsOpenSSL" >> cabal.project.local
echo " flags: -homebrew-openssl" >> cabal.project.local
echo "" >> cabal.project.local
caution

More recent versions of MacOS seems to install openssl in a different location than expected by default. If you have installed openssl via homebrew and encounter the following build error:

Failed to build HsOpenSSL-0.11.7.2. The failure occurred during the configure
step.
[1 of 1] Compiling Main (...)
Linking .../dist-newstyle/tmp/src-75805/HsOpenSSL-0.11.7.2/dist/setup/setup ...
Configuring HsOpenSSL-0.11.7.2...
setup: Can’t find OpenSSL library

You'll most likely need to add relevant symlinks as follows:

sudo mkdir -p /usr/local/opt/openssl
sudo ln -s /opt/homebrew/opt/openssl@3/lib /usr/local/opt/openssl/lib
sudo ln -s /opt/homebrew/opt/openssl@3/include /usr/local/opt/openssl/include

This is a wart of the HsOpenSSL library wrapper, and using classic methods such as setting LDFLAGS & CPPFLAGS, or using --extra-include-dirs and --extra-lib-dirs won't work properly.

Building and installing the node

Build the node and CLI with cabal:

cabal update
cabal build exe:cardano-node
cabal build exe:cardano-cli
caution

On Windows, should you run into an error like this one when building:

ld.lld: error: undefined symbol: __local_stdio_printf_options
>>> referenced by libHSprocess-1.6.25.0-4d1c620770857b639d352d5e988299133f830295.a(runProcess.o):(swprintf_s)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

You should comment out extra-lib-dirs and extra-include-dirs in ~/AppData/Roaming/cabal/config. See this ticket for an example.

Install the newly built node and CLI commands to the ~/.local/bin directory:

mkdir -p ~/.local/bin
cp -p "$(cabal list-bin cardano-node)" ~/.local/bin/
cp -p "$(cabal list-bin cardano-cli)" ~/.local/bin/

Note: If cardano-cli does not build with 'cabal build all', run 'cabal build cardano-cli'. Note: ~/.local/bin should be in 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:

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

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

Note: If serialization of the ledger state changed, snapshots in your db/ledger folder will be deleted by the node on startup. Consider backing those up before starting a new version of the node.