Install Cardano node Mac

From Cardano Blockchain Wiki
Jump to navigation Jump to search
System Requirements
Testnet hardware
CPUx86/x64 two+ cores
RAM4GB
HDD30GB+
Mainnet hardware
CPUx86/x64 two+ cores
RAM16GB
HDD100GB+
Dependencies and packages
GitFree and open source distributed version control system originally developed by Linus Torvalds https://git-scm.com/
GCCThe GNU Compiler Collection includes front ends for C, C++ https://gcc.gnu.org/
GMPA free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers https://gmplib.org/
ncursesA programming library providing an API for writing text-based user interfaces (TUI) in a terminal-independent manner https://invisible-island.net/ncurses
systemdA suite of basic building blocks for a Linux system https://www.freedesktop.org/wiki/Software/systemd/
zlibfree, general-purpose library for lossless data-compression https://zlib.net/
Cabal 3.6.2.0The system for building and packaging Haskell libraries and programs https://www.haskell.org/cabal
GHC 8.10.7a state-of-the-art compiler and interactive environment for Haskell https://www.haskell.org/ghc

The page describes the installation process of cardano-node and cardano-cli on a MacOS operating system from the source code.

cardano-node and cardano-cli are two essential components of Cardano blockchain, cardano-node is essentially a container that implements several components such as networking, consensus, and storage. Full block-producing nodes have a responsibility to validate transactions, execute smart contracts, and produce blocks. Cardano CLI is the utility direct socket connection to cardano-node installed and by that gives full access to Cardano blockchain.

Both of the components installed and running will let:

  • keys generation, transaction construction, certificate creation
  • sending, receiving, querying transactions
  • transaction metadata submission
  • native tokens creation
  • minting NFTs
  • stake pool operation
  • smart contracts execution

Step 1 - System Packages

Building Cardano from sources on Mac require Git, GCC, GMP, ncurses, systemd, Zlib available in the system, which themselves can be installed with Homebrew - Package Manager for macOS and require Xcode Command Line Tools presented in the system.

To install Xcode Command Line Tools, run in the command line:

xcode-select --install

To install brew, run in the command line:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install the required libraries with homebrew, by entering one by one in the terminal: ‎

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

Install llvm if case of M1, M2 Apple ARM CPU with: ‎

brew install llvm

Step 2 - GHC and Cabal​

GHC - is the most commonly used Haskell compiler. Cabal - is a system for building and packaging Haskell libraries and programs.

GHC(Glasgow Haskell Compiler) and Cabal(Common Architecture for Building Applications and Libraries) are packages needed for the compilation and building of the sources and managed by GHCup - general purpose installer for Haskell language.

Install GHCup with:‎

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

Running GHCup installer will require necessary input from the command line. ‎

Do you want ghcup to automatically add the required PATH variable to "/Users/user/.bashrc"? - (P or enter)
Do you want to install haskell-language-server (HLS)? - (N or enter)
Do you want to install stack? - (N or enter)
Press ENTER to proceed or ctrl-c to abort. (enter)

At the end of the installation, GHCup will automatically detect the shell used and add new environment variables at the bottom after which the shell sessions should be restarted. Alternatively, the shell can be reloaded with the command source $HOME/.bashrc, or source $HOME/.zshrc in case if zsh is used.

Ensure GHC and Cabal were installed on the host Linux system with the command:

ghcup --version

Expected output:

The GHCup Haskell installer, version v0.1.17.8

IOHK suggests using GHC 8.10.7 and Cabal 3.6.2.0, which could be picked up by telling GHCup to install and switch to the required versions: ‎

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

Ensure the correct version of GHC and Cabal versions are installed with the command:

ghc --version
cabal --version

Expected output:

The Glorious Glasgow Haskell Compilation System, version 8.10.7
cabal-install version 3.6.2.0
compiled using version 3.6.2.0 of the Cabal library

Step 3 - Sources compilation

Compilation of cardano-node requires compilation and two dependency libraries: Secp256k1 and secp256k1.

  • libsodium - a modern, portable, easy-to-use crypto library
  • libsecp256k1 - optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1

A good practice to keep source codes and builds in the $HOME/cardano-src directory, to make one command:‎

mkdir -p $HOME/cardano-src
cd $HOME/cardano-src

Download, compile, and install libsodium:‎

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

Update the shell by adding two environment variables, so the compiler can be aware that libsodium is installed on your Linux host. Type nano $HOME/.zshrc(or nano $HOME/.bashrc) and add to the bottom:

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

Restart or reload the shell afterwards with the command: source $HOME/.bashrc, or source $HOME/.zshrc in case of Zsh.

Download, compile, and install libsecp256k1:‎

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

Download, compile, and install cardano-node(cardano-cli is included):

cd $HOME/cardano-src
git clone https://github.com/input-output-hk/cardano-node.git
cd cardano-node
git fetch --all --recurse-submodules --tags
git checkout $(curl -s https://api.github.com/repos/input-output-hk/cardano-node/releases/latest | jq -r .tag_name)

Step 4 - Building binaries​

For correct building GHC is required to be configured to the version recommended by IOHK by running:

cabal configure --with-compiler=ghc-8.10.7

And one more step for Linux hosts on ARM platforms which require additional configuration for LLVM:‎

sudo apt install llvm-9
sudo apt install clang-9 libnuma-dev
sudo ln -s /usr/bin/llvm-config-9 /usr/bin/llvm-config
sudo ln -s /usr/bin/opt-9 /usr/bin/opt
sudo ln -s /usr/bin/llc-9 /usr/bin/llc
sudo ln -s /usr/bin/clang-9 /usr/bin/clang

Build Haskell-based cardano-node to produce executable binaries: ‎

cabal build cardano-node cardano-cli

Install cardano-node and cardano-cli commands to the $HOME/.local/bin directory with:

mkdir -p $HOME/.local/bin
cp -p "$(./scripts/bin-path.sh cardano-node)" $HOME/.local/bin/
cp -p "$(./scripts/bin-path.sh cardano-cli)" $HOME/.local/bin/

Update $HOME/.bashrc by adding export PATH="$HOME/.local/bin/:$PATH" to the end and restart shell or reload source $HOME/.bashrc profile, use source $HOME/.zshrc in case of Zsh.

See the version installed by typing:‎

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

Successful installation should display the versions installed:

cardano-cli 1.35.1 - darwin-aarch64 - ghc-8.10
git rev c23d5d319cd3276575c6ac32458516232e8d2c48
cardano-node 1.35.1 - darwin-aarch64 - ghc-8.10
git rev c23d5d319cd3276575c6ac32458516232e8d2c48

Cardano node and cli are now configured and ready for usage.