# Build from source

This document describes how to build an Aeternity node from source on:

* Ubuntu 20.04 LTS
* MacOS (latest)
* Archlinux 20210404
* openSUSE Leap 15.2

While the package should build on most linux distributions that's not verified (in CI) for each release on other than the below platforms:

* Ubuntu 18.04 LTS
* MacOS (latest)

The commands below assume you are logged in with `sudo` user.

The node have couple of main dependencies that have to be installed to build it from source:

* [Erlang/OTP 24.3.4.15](http://erlang.org/doc/installation_guide/INSTALL.html)
* [Libsodium](https://download.libsodium.org/doc/installation/)
* [Libgmp](https://gmplib.org)

## Dependencies

### Ubuntu 20.04

Update package database, packages and install the common tools and libraries:

```bash
sudo apt-get -qq update \
&& sudo apt-get -y upgrade \
&& sudo apt-get -qq -y install git autoconf libtool build-essential cmake erlang libsodium-dev libgmp-dev
```

#### Building with dynamically linked RocksDB

To speed up build times, you can tell the RocksDB bindings to use dynamically loaded system libraries instead of building everything from source with static linking. You can do this by setting the following environment variable:

```bash
export ERLANG_ROCKSDB_OPTS="-DWITH_SYSTEM_ROCKSDB=ON -DWITH_LZ4=ON -DWITH_SNAPPY=ON"
```

You must then also install the corresponding libraries on your system: `sudo apt install librocksdb-dev liblz4-dev libsnappy-dev`.

### MacOS

The easiest way to install package on MacOS is Homebrew, it can be installed by running:

```bash
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```

Then install the build dependencies using the `brew` command:

```
brew update
brew install erlang@24 openssl libsodium autoconf gmp cmake automake
```

If building on an m1 Mac homebrew does not automatically set up symlinks to system directories, so before running `make` set up the build path with:

```bash
export PATH=/opt/homebrew/bin:$PATH
export CFLAGS="-I/opt/homebrew/include"
export CXXFLAGS="-I/opt/homebrew/include"
export LDFLAGS="-L/opt/homebrew/lib"
```

### Archlinux

Update package database, packages and install the common tools and libraries:

```bash
sudo pacman -Sy
sudo pacman -S git base-devel cmake ncurses erlang23-nox libsodium gmp
```

### openSUSE Leap 15.2

```bash
sudo zypper install -t pattern devel_basis
sudo zypper install cmake gcc-c++ git erlang libsodium-devel gmp-devel
```

## Building

The source code of the Aeternity node can be obtained by cloning the public [GitHub repository](https://github.com/aeternity/aeternity):

```bash
git clone https://github.com/aeternity/aeternity.git aeternity_source && cd aeternity_source
```

**NOTE**: By default git will checkout the `master` (default) branch of the source code. To build a particular version it should be checkout first:

```bash
VERSION=X.Y.Z # set a particular version
git checkout tags/v${VERSION:?}
```

### Production build

One can create a production build by running:

```bash
make prod-build
```

If `prod-build` went fine, configuration is in place, one should be able to navigate to the build artifacts directory and start the Aeternity node:

```bash
cd _build/prod/rel/aeternity/
bin/aeternity daemon
```

See [operation documentation](/developer-documentation/aeternity/docs/operation.md) for more details.

### Production package

Alternatively a production package similar to what is distributed via [GitHub releases](https://github.com/aeternity/aeternity/releases) can be created by running:

```bash
make prod-package
```

Once the packaging is done, the package is created in the `_build/prod/rel/aeternity/` directory, e.g. `_build/prod/rel/aeternity/aeternity-X.Y.Z.tar.gz`.

To deploy the package for example in `~/aeternity/node` one should just unarchive it to that directory:

```bash
mkdir -p ~/aeternity/node
tar xf _build/prod/rel/aeternity/aeternity-*.tar.gz -C ~/aeternity/node
```

Then start the node in background mode:

```bash
~/aeternity/node/bin/aeternity daemon
```

See [operation documentation](/developer-documentation/aeternity/docs/operation.md) for more details.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aeternity.com/developer-documentation/aeternity/docs/build.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
