# Build Linux binary from source and become a Sentry Node Operator

### Preresquites <a href="#preresquites" id="preresquites"></a>

#### Operating System <a href="#operating-system" id="operating-system"></a>

This tutorial assumes that your node is running Ubuntu LTS version (i.e: 18.04, 20.04 or 22.04). It does not work with Ubuntu 16.04 or older versions.

#### Go version <a href="#go-version" id="go-version"></a>

The Golang version should be from 1.18 and above If you have not installed it yet, you can refer to [this document](https://github.com/oraichain/docs/blob/master/developer/tutorials/install-go.md).

Make sure that `$GOPATH` is in your `$PATH`. It's the crucial part of this tutorial.

#### Make <a href="#make" id="make"></a>

If your node does not have Make, install using: `sudo apt update && sudo apt install make`

#### Gcc <a href="#gcc" id="gcc"></a>

You need to install Gcc to build the binary. Type: `sudo apt update && sudo apt install gcc`

### Build the binary from source <a href="#build-the-binary-from-source" id="build-the-binary-from-source"></a>

Please define the `$ORAI_HOME` environment variable which will be used as the working directory, in this tutorial we will assume that your `$ORAI_HOME` is `root`. If you don't define it, all of the following installations will be using your `$HOME` folder as `$ORAI_HOME`, please replace `$ORAI_HOME` with `$HOME` in the corresponding commands (except export ORAI\_HOME command).

Make sure your user has enough permissions to write data to the `$ORAI_HOME` folder.

Copy

```
# Export ORAI_HOME env variable
export ORAI_HOME="/root"
```

Copy

```
# clone the Oraichain network repository
cd $ORAI_HOME
git clone https://github.com/oraichain/orai.git

# enter the repo
cd orai

# checkout the latest tag
git checkout <tag>
```

The `<version-tag>` will need to be set to either a testnet or the latest mainnet version tag.

The current mainnet version tag will be `v0.41.7-1s-block-time` - i.e:

Copy

```
git checkout v0.41.7-1s-block-time
```

Next, you should be able to build the binary file using the below command:

Copy

```
# go to main folder ($ORAI_HOME/orai/orai)
cd orai
go mod tidy
make install
```

After running the above commands, your `oraid` binary can be found in `$GOPATH/bin`. To confirm that the installation is succeeded, you can run (please make sure that `$GOPATH/bin` is in your `$PATH`):

Copy

```
oraid version
```

The current binary version for Linux users is v0.41.7-1s-block-time

Libwasmvm version: `oraid query wasm libwasmvm-version`, which should give: 1.5.2

### Initialize Orai Node <a href="#initialize-orai-node" id="initialize-orai-node"></a>

Use oraid to initialize your node (replace the NODE\_NAME with a name of your choosing):

Copy

```
oraid init NODE_NAME --home $ORAI_HOME/.oraid
```

Download and place the genesis file in the orai config folder:

Copy

```
wget -O $ORAI_HOME/.oraid/config/genesis.json https://raw.githubusercontent.com/oraichain/oraichain-static-files/master/genesis.json
```

#### Finally, your working directory should be like below: <a href="#finally-your-working-directory-should-be-like-below" id="finally-your-working-directory-should-be-like-below"></a>

Copy

```
#tree $ORAI_HOME/.oraid/
$ORAI_HOME/.oraid/
├── config
│   ├── app.toml
│   ├── client.toml
│   ├── config.toml
│   ├── genesis.json
│   ├── node_key.json
│   └── priv_validator_key.json
└── data
    └── priv_validator_state.json
```

2 directories, 7 files

### Set Up Cosmovisor <a href="#set-up-cosmovisor" id="set-up-cosmovisor"></a>

(You may also refer to the Cosmovisor [installation instructions](https://github.com/cosmos/cosmos-sdk/tree/main/tools/cosmovisor#installation).) Set up cosmovisor to ensure any future upgrades happen flawlessly. To install Cosmovisor:

Copy

```
go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest
```

Create the required directories, and Copy the current oraid binary into the cosmovisor/genesis folder:

Copy

```
mkdir -p $ORAI_HOME/.oraid/cosmovisor
mkdir -p $ORAI_HOME/.oraid/cosmovisor/genesis
mkdir -p $ORAI_HOME/.oraid/cosmovisor/genesis/bin
mkdir -p $ORAI_HOME/.oraid/cosmovisor/upgrades
cp $GOPATH/bin/oraid $ORAI_HOME/.oraid/cosmovisor/genesis/bin
```

Set the environment variables

Copy

```
echo "# Setup Cosmovisor" >> ${HOME}/.profile
echo "export ORAI_HOME=/root" >> ${HOME}/.profile
echo "export DAEMON_NAME=oraid" >> ${HOME}/.profile
echo "export DAEMON_HOME=$HOME/.oraid" >> ${HOME}/.profile
echo "export DAEMON_ALLOW_DOWNLOAD_BINARIES=false" >> ${HOME}/.profile
echo "export DAEMON_LOG_BUFFER_SIZE=512" >> ${HOME}/.profile
echo "export DAEMON_RESTART_AFTER_UPGRADE=true" >> ${HOME}/.profile
echo "export UNSAFE_SKIP_BACKUP=true" >> ${HOME}/.profile
source ~/.profile
```

To check your work, ensure the version of cosmovisor and oraid are the same:

Copy

```
cosmovisor version
oraid version
```

#### Finally, your working directory should be like below: <a href="#finally-your-working-directory-should-be-like-below-1" id="finally-your-working-directory-should-be-like-below-1"></a>

Copy

```
$ORAI_HOME/.oraid/
├── config
│   ├── app.toml
│   ├── client.toml
│   ├── config.toml
│   ├── genesis.json
│   ├── node_key.json
│   └── priv_validator_key.json
├── cosmovisor
│   ├── current -> /root/.oraid/cosmovisor/genesis
│   ├── genesis
│   │   └── bin
│   │       └── oraid
│   └── upgrades
└── data
    └── priv_validator_state.json
```

7 directories, 8 files

### Download Chain Data <a href="#download-chain-data" id="download-chain-data"></a>

Download liblz4-tool to handle the compressed file, then Download & Decompress the snapshot:

Copy

```
cd $ORAI_HOME/.oraid
sudo apt-get install wget liblz4-tool aria2 -y
wget -O oraichain_latest.tar.lz4 https://orai.s3.us-east-2.amazonaws.com/snapshots/oraichain_latest.tar.lz4
lz4 -c -d oraichain_latest.tar.lz4 | tar -x -C $ORAI_HOME/.oraid
```

#### Optional (problem with binnary version v0.41.6) <a href="#optional-problem-with-binnary-version-v0.41.6" id="optional-problem-with-binnary-version-v0.41.6"></a>

In the data folder, if the file upgrade-info.json does not exist, you can ignore this section. Otherwise, open the upgrade-info.json file and check the version.

Copy

```
cat $ORAI_HOME/.oraid/data/upgrade-info.json
```

If version is not "v0.41.6" then delete this file

Copy

```
rm $ORAI_HOME/.oraid/data/upgrade-info.json
```

### Edit config <a href="#edit-config" id="edit-config"></a>

Copy

```
vim $ORAI_HOME/.oraid/config/config.toml
```

Update seed address

Copy

```
seeds = "e18f82a6da3a9842fa55769955d694f62f7f48bd@seed1.orai.zone:26656,893f246ffdffae0a9ef127941379303531f50d5c@seed2.orai.zone:26656,4fa7895fc43f618b53cd314585b421ee47b75639@seed3.orai.zone:26656,defeea41a01b5afdb79ef2af155866e122797a9c@seed4.orai.zone:26656"
```

### Set Up Orai Service <a href="#set-up-orai-service" id="set-up-orai-service"></a>

Set up a service to allow cosmovisor to run in the background as well as restart automatically if it runs into any problems:

Copy

```
cat > /tmp/orai.service <<EOF
[Unit]
Description=Cosmovisor daemon
After=network-online.target
[Service]
Environment="ORAI_HOME=/root"
Environment="DAEMON_NAME=oraid"
Environment="DAEMON_HOME=${ORAI_HOME}/.oraid"
Environment="DAEMON_RESTART_AFTER_UPGRADE=true"
Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false"
Environment="DAEMON_LOG_BUFFER_SIZE=512"
Environment="UNSAFE_SKIP_BACKUP=true"
User=$USER
ExecStart=$GOPATH/bin/cosmovisor run start --home ${ORAI_HOME}/.oraid --minimum-gas-prices=0.001orai
Restart=always
RestartSec=3
LimitNOFILE=infinity
LimitNPROC=infinity
[Install]
WantedBy=multi-user.target
EOF
```

Move this new file to the systemd directory:

Copy

```
sudo mv /tmp/orai.service /etc/systemd/system/orai.service
```

Reload and start the service:

Copy

```
sudo systemctl daemon-reload
sudo systemctl restart systemd-journald
sudo systemctl start orai
sudo systemctl enable orai
```

Check the status of the service:

Copy

```
sudo systemctl status orai
```

To see live logs of the service:

Copy

```
journalctl -u orai -f
```

Check your node status

Copy

```
oraid status
# OR
oraid status 2>&1 | jq .SyncInfo
# OR
curl -s localhost:26657/status | grep "catching_up"
# OR
oraid status 2>&1 | jq .SyncInfo.check_status
```

If the catching\_up status is false, your node finishes syncing process. Finally, you can delete the snapshot file and backup your config folder. The snapshot file may be outdated; you can reach out to our community for it. Please join the [Oraichain validators group](https://t.me/joinchat/yH9nMLrokQRhZGY1) on Telegram to discuss ideas and problems!
